34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using Brizco.Domain.Entities.Task;
|
|
|
|
namespace Brizco.Core.CoreServices;
|
|
|
|
public class PageService : IPageService
|
|
{
|
|
private readonly ICurrentUserService _currentUserService;
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public PageService(ICurrentUserService currentUserService,IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_currentUserService = currentUserService;
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<AppDashboardPageDto> GetAppDashboardAsync(CancellationToken cancellationToken)
|
|
{
|
|
if (_currentUserService.UserId == null)
|
|
throw new AppException("User id is null ");
|
|
if (Guid.TryParse(_currentUserService.UserId, out Guid userId)!)
|
|
throw new AppException("User id is wrong");
|
|
|
|
var todayTasks = await _repositoryWrapper.SetRepository<Activity>()
|
|
.TableNoTracking
|
|
.Where(a => a.UserId == userId)
|
|
.ToListAsync(cancellationToken);
|
|
|
|
return new AppDashboardPageDto
|
|
{
|
|
DoneActivitiesToday = todayTasks.Count(t => t.IsDone),
|
|
TotalActivitiesToday = todayTasks.Count,
|
|
UnDoneActivitiesToday = todayTasks.Count(t => t.IsDone!)
|
|
};
|
|
}
|
|
} |