public ChartDataVm GetChartDate(AnalyticsChartDataParams @params) { return(AnalyticsService.GetChartData(@params)); }
public ChartDataVm GetChartData(AnalyticsChartDataParams @params) { var result = new ChartDataVm(); var impQuery = ImportRepository.ImportedFilesQuery(); var delQuery = ImportRepository.FileUploadQuery().Include(f => f.ImportedFile); if (@params.MasterAccountId != 0) { impQuery = impQuery.Where(f => f.MasterAccountId == @params.MasterAccountId); delQuery = delQuery.Where(f => f.ImportedFile.MasterAccountId == @params.MasterAccountId); } if (@params.FtpCredentialId != 0) { impQuery = impQuery.Where(f => f.FtpCredentialId == @params.FtpCredentialId); delQuery = delQuery.Where(f => f.ImportedFile.FtpCredentialId == @params.FtpCredentialId); } var srcFilesData = new ChartDataVm.DataSet { Label = "Source files" }; var impFilesData = new ChartDataVm.DataSet { Label = "Imported files" }; var delFilesData = new ChartDataVm.DataSet { Label = "ZOHO files" }; var sentFilesData = new ChartDataVm.DataSet { Label = "Sent ZOHO files" }; var periods = @params.Periods.ToPeriodList().ToList(); periods.ToList().ForEach(period => { var srcFiles = impQuery.Count(f => DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) && DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate)); var impFiles = impQuery.Count(f => DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) && DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate) && f.ImportedDate != null); var delFiles = delQuery.Count(f => DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) && DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate)); var sentFiles = delQuery.Count(f => f.IsSent && DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) && DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate)); srcFilesData.Data.Add(srcFiles); impFilesData.Data.Add(impFiles); delFilesData.Data.Add(delFiles); sentFilesData.Data.Add(sentFiles); }); result.Data = new[] { srcFilesData, impFilesData, delFilesData, sentFilesData }; result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray(); return(result); }