public async Task <Result <DashboardDataResponse> > Handle(GetDashboardDataQuery query, CancellationToken cancellationToken) { var response = new DashboardDataResponse { ProductCount = await _unitOfWork.Repository <Product>().Entities.CountAsync(cancellationToken), BrandCount = await _unitOfWork.Repository <Brand>().Entities.CountAsync(cancellationToken), UserCount = await _userService.GetCountAsync(), RoleCount = await _roleService.GetCountAsync() }; var selectedYear = DateTime.Now.Year; double[] productsFigure = new double[13]; double[] brandsFigure = new double[13]; for (int i = 1; i <= 12; i++) { var month = i; var filterStartDate = new DateTime(selectedYear, month, 01); var filterEndDate = new DateTime(selectedYear, month, DateTime.DaysInMonth(selectedYear, month), 23, 59, 59); // Monthly Based productsFigure[i - 1] = await _unitOfWork.Repository <Product>().Entities.Where(x => x.CreatedOn >= filterStartDate && x.CreatedOn <= filterEndDate).CountAsync(cancellationToken); brandsFigure[i - 1] = await _unitOfWork.Repository <Brand>().Entities.Where(x => x.CreatedOn >= filterStartDate && x.CreatedOn <= filterEndDate).CountAsync(cancellationToken); } response.DataEnterBarChart.Add(new ChartSeries { Name = _localizer["Products"], Data = productsFigure }); response.DataEnterBarChart.Add(new ChartSeries { Name = _localizer["Brands"], Data = brandsFigure }); return(await Result <DashboardDataResponse> .SuccessAsync(response)); }
public async Task <IActionResult> GetDashboardData() { var claimsIdentity = this.User.Identity as ClaimsIdentity; var userId = claimsIdentity.Claims.ToList().FirstOrDefault(x => x.Type == "id").Value; var command = new GetDashboardDataQuery { UserId = userId }; return(await _mediator.Send(command)); }
public async Task <Result <DashboardDataResponse> > Handle(GetDashboardDataQuery query, CancellationToken cancellationToken) { var response = new DashboardDataResponse(); response.ProductCount = await _unitOfWork.Repository <Product>().Entities.CountAsync(); response.BrandCount = await _unitOfWork.Repository <Brand>().Entities.CountAsync(); response.UserCount = await _userService.GetCountAsync(); response.RoleCount = await _roleService.GetCountAsync(); return(Result <DashboardDataResponse> .Success(response)); }
public async Task <ActionResult <DashboardViewModel> > GetDashboardSummary([FromQuery] GetDashboardDataQuery query) { var result = await _Mediator.Send(query); return(Ok(result)); }