public async Task <ActionResult> GetChartReport([FromQuery] int storeId, [FromQuery] string userName, [FromQuery] Enums.ReportType reportType) { var reportDto = new GetChartReportDto(); reportDto.StoreId = storeId; reportDto.ReportType = reportType; reportDto.UserName = userName; var chartReport = await _storeRepository.GetChartReport(reportDto); return(Ok(chartReport)); }
public async Task <ChartReportDto> GetChartReport(GetChartReportDto reportDto) { ChartReportDto chartReport = new ChartReportDto(); #region Current Store Info var store = await _context.Store .Include(x => x.StoreStockDetail) .FirstOrDefaultAsync(x => x.Id == reportDto.StoreId); chartReport.StoreReport.Accuracy = store.StoreStockDetail.Accuracy; chartReport.StoreReport.MeanAgeInDays = store.StoreStockDetail.MeanAgeInDays; chartReport.StoreReport.OnFloorAvailability = store.StoreStockDetail.OnFloorAvailability; chartReport.StoreReport.TotalStock = store.StoreStockDetail.TotalStock; #endregion switch (reportDto.ReportType) { case Infrastructure.Enums.ReportType.Max: #region Max values chartReport.GeneralReport.Accuracy = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Max(y => y.Accuracy) ).FirstOrDefaultAsync(); chartReport.GeneralReport.MeanAgeInDays = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Max(y => y.MeanAgeInDays) ).FirstOrDefaultAsync(); chartReport.GeneralReport.OnFloorAvailability = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Max(y => y.OnFloorAvailability) ).FirstOrDefaultAsync(); chartReport.GeneralReport.TotalStock = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Max(y => y.TotalStock) ).FirstOrDefaultAsync(); #endregion break; case Infrastructure.Enums.ReportType.Mean: #region Mean values chartReport.GeneralReport.Accuracy = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Average(y => y.Accuracy) ).FirstOrDefaultAsync(); chartReport.GeneralReport.MeanAgeInDays = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Average(y => y.MeanAgeInDays) ).FirstOrDefaultAsync(); chartReport.GeneralReport.OnFloorAvailability = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Average(y => y.OnFloorAvailability) ).FirstOrDefaultAsync(); chartReport.GeneralReport.TotalStock = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Average(y => y.TotalStock) ).FirstOrDefaultAsync(); #endregion break; case Infrastructure.Enums.ReportType.Min: #region Min values chartReport.GeneralReport.Accuracy = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Min(y => y.Accuracy) ).FirstOrDefaultAsync(); chartReport.GeneralReport.MeanAgeInDays = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Min(y => y.MeanAgeInDays) ).FirstOrDefaultAsync(); chartReport.GeneralReport.OnFloorAvailability = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Min(y => y.OnFloorAvailability) ).FirstOrDefaultAsync(); chartReport.GeneralReport.TotalStock = await _context.SystemUser. Include(x => x.Stores) .ThenInclude(x => x.StoreStockDetail) .Where(x => x.UserName == reportDto.UserName) .Select ( x => x.Stores .Select(y => y.StoreStockDetail) .Min(y => y.TotalStock) ).FirstOrDefaultAsync(); #endregion break; } return(chartReport); }