protected override async Task <Report> OnGenerateFilteredReportResultAsync(WidgetDataSourceContext context) { if (this.ReportModelId.HasValue == false) { throw new OrionsException($"No {nameof(ReportModelId)} assigned"); } var reportModelConfig = await context.HyperStore.RetrieveAsync <ReportModelConfig>(this.ReportModelId.Value); if (context.GroupFilterData?.StartTime.HasValue == true || context.GroupFilterData?.EndTime.HasValue == true) { reportModelConfig.TrySetTimeRange(context.GroupFilterData?.StartTime, context.GroupFilterData?.EndTime); } if (context.GroupFilterData?.Period != null) { reportModelConfig.TrySetPeriod(context.GroupFilterData.Period); } if (context.GroupFilterData?.FilterLabels?.Length > 0) { reportModelConfig.TrySetLabels(context.GroupFilterData?.FilterLabels, context.GroupFilterData.FilterTarget); } if (MetadataSetId.HasValue) { var metadataSetStage = reportModelConfig.DataSource as MetadataSetReportDataSourceStageConfig; if (metadataSetStage != null) { metadataSetStage.MetadataSetId = MetadataSetId; } else { Logger.Instance?.Warning(this, nameof(OnGenerateFilteredReportResultAsync), "Failed to apply MetadataSetId, since source stage is not a metadataset stage"); } } var helper = new ReportModelHelper(); if (this.JobMode) { return(await helper.ExecuteJobModeAsync(context.HyperStore, reportModelConfig, null, context.CancellationToken, "", this.JobMode_CacheRead, this.JobMode_CacheWrite)); } else { return(await helper.ExecuteLocalModeAsync(context.HyperStore, reportModelConfig, null, "", context.Logger, context.CancellationToken)); } }
public dynamic GetWorkingHoursByOwnerParams(ProjectActivitiesOwnerParameters ownerParams) { if (ownerParams.DateFormatSelected == "dd") { var query = from p in _appDbContext.Project join pi in _appDbContext.Projectinfo on p.ProjectId equals pi.ProjectId into q1 from pi in q1 where p.ProjectId == ownerParams.ProjectId group new { p.ProjectId, p.Name, pi.HoursWorked, pi.Date } by new { p.ProjectId, p.Name, pi.Date } into q select new { ProjectId = q.Key.ProjectId, Name = q.Key.Name, Date = q.Key.Date, Day = q.Key.Date.Day, q.Key.Date.Month, q.Key.Date.Year, ProjectWorkingHours = q.Sum(c => c.HoursWorked) }; return(query.OrderBy(c => c.Month).ThenBy(c => c.Day).ToList()); } else if (ownerParams.DateFormatSelected == "mm") { var query = from p in _appDbContext.Project join pi in _appDbContext.Projectinfo on p.ProjectId equals pi.ProjectId into q1 from pi in q1.DefaultIfEmpty() where p.ProjectId == ownerParams.ProjectId group new { p.ProjectId, p.Name, pi.HoursWorked, pi.Date } by new { p.ProjectId, p.Name, pi.Date.Month, pi.Date.Year } into q select new { ProjectId = q.Key.ProjectId, Name = q.Key.Name, q.Key.Month, q.Key.Year, ProjectWorkingHours = q.Sum(c => c.HoursWorked) }; return(query.ToList().OrderBy(c => c.Month)); } else if (ownerParams.DateFormatSelected == "ww") { var query = from p in _appDbContext.Project join pi in _appDbContext.Projectinfo on p.ProjectId equals pi.ProjectId into q1 from pi in q1.DefaultIfEmpty() where p.ProjectId == ownerParams.ProjectId group new { p.ProjectId, p.Name, pi.HoursWorked, pi.Date } by new { p.ProjectId, p.Name, pi.Date, pi.Date.Month, pi.Date.Year } into q select new { ProjectId = q.Key.ProjectId, Name = q.Key.Name, WeekNumber = ReportFacade.GetWeekNumberOfMonth(q.Key.Date), q.Key.Month, q.Key.Year, ProjectWorkingHours = q.Sum(c => c.HoursWorked) }; var queryResult = query.ToList(); Dictionary <int, ReportModelHelper> modelDic = new Dictionary <int, ReportModelHelper>(); for (int i = 0; i < queryResult.Count(); i++) { int projectId = queryResult.ElementAt(i).ProjectId; int weekNumber = queryResult.ElementAt(i).WeekNumber; int monthNumber = queryResult.ElementAt(i).WeekNumber; ReportModelHelper model = new ReportModelHelper() { WeekNumber = queryResult.ElementAt(i).WeekNumber, Year = queryResult.ElementAt(i).Year, Month = queryResult.ElementAt(i).Month, TotalWorkingHours = queryResult .Where(c => c.WeekNumber == weekNumber) .Sum(c => c.ProjectWorkingHours) }; if (!modelDic.ContainsKey(model.WeekNumber)) { modelDic.Add(model.WeekNumber, model); } } return(modelDic.Select(c => c.Value).OrderBy(x => x.Month).ThenBy(c => c.WeekNumber).ToList()); } return(null); }