protected async Task <TracktorWebModel> GenerateWebModel(bool updateOnly = false) { var summaryModel = await _service.GetSummaryModelAsync(Context); return(new TracktorWebModel { SummaryModel = summaryModel, EntriesModel = await _service.GetEntriesModelAsync(Context, null, null, 0, 0, 20), StatusModel = await _service.GetStatusModelAsync(Context), EditModel = updateOnly ? null : new TEditModelDto { Entry = new TEntryDto { EndDate = DateTime.UtcNow, StartDate = DateTime.UtcNow, IsDeleted = false, InProgress = false, TaskName = "", ProjectName = "", TTaskID = 0, TEntryID = 0, Contrib = 0, } }, ReportModel = updateOnly ? null : WebReportModel.Create(summaryModel, DateTime.UtcNow) }); }
public TracktorWebModel Get(int year, int month, int projectID, int taskID) { var summaryModel = _service.GetSummaryModel(Context); var startDate = new DateTime(year, month, 1, 0, 0, 0, DateTimeKind.Local); var endDate = startDate.AddMonths(1); var reportModel = _service.GetReportModel(Context, startDate, endDate, projectID, taskID); var webReport = WebReportModel.Create(summaryModel, startDate); var reportStart = startDate.StartOfWeek(DayOfWeek.Monday); var reportEnd = endDate.StartOfWeek(DayOfWeek.Monday).AddDays(6); var rollingDate = reportStart; WebReportWeek currentWeek = null; while (rollingDate <= reportEnd) { if (rollingDate.DayOfWeek == DayOfWeek.Monday) { if (currentWeek != null) { webReport.Report.Add(currentWeek); } currentWeek = new WebReportWeek(rollingDate); } double contrib = 0; if (reportModel.DayContribs.ContainsKey(rollingDate)) { contrib = reportModel.DayContribs[rollingDate]; } var currentDay = new WebReportDay(rollingDate, contrib, month); currentWeek.Days.Add(currentDay); if (currentDay.InFocus) { currentWeek.Contrib += contrib; webReport.Contrib += contrib; } rollingDate = rollingDate.AddDays(1); } if (currentWeek != null) { webReport.Report.Add(currentWeek); } foreach (var project in summaryModel.Projects.Where(p => projectID == 0 || p.TProjectID == projectID)) { var projectContrib = new WebReportProjectContrib { ProjectName = project.Name, TaskContribs = new List <WebReportTaskContrib>(), Contrib = 0 }; foreach (var task in project.TTasks.Where(t => taskID == 0 || t.TTaskID == taskID)) { var taskContrib = new WebReportTaskContrib { TaskName = task.Name, Contrib = 0 }; if (reportModel.TaskContribs.ContainsKey(task.TTaskID)) { taskContrib.Contrib = reportModel.TaskContribs[task.TTaskID]; } projectContrib.TaskContribs.Add(taskContrib); projectContrib.Contrib += taskContrib.Contrib; } webReport.ProjectContribs.Add(projectContrib); } return(new TracktorWebModel { ReportModel = webReport }); }