public IEnumerable <TimeSheetJson> GetPreviousPeriod(WorkHourJson workHourJson) { List <TimeSheetJson> result = new List <TimeSheetJson>(); if (workHourJson == null) { workHourJson = new WorkHourJson(); workHourJson.Date = DateTime.Now; } var startDate = workHourJson.Date; UnitOfWork uow = new UnitOfWork(); UserManager userManager = new UserManager(uow); ProjectManager projectManager = new Domain.ProjectManager(uow); TimeSheetManager timeSheetManager = new TimeSheetManager(uow); DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(uow); //SyncWithPWA(uow); User currUser = new UserHelper().GetCurrent(); DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser); var dt = startDate.AddDays(-1); DateTime fromDate = dt.AddDays(-displayPeriod.NumOfDays); DateTime toDate = dt; if (displayPeriod.IsWeekly) { fromDate = dt.StartOfWeek(DayOfWeek.Saturday); toDate = dt.EndOfWeek(DayOfWeek.Friday); IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate); IEnumerable <WorkHour> workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate); result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours); } else { IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate); IEnumerable <WorkHour> workHours = timeSheetManager.GetWorkHoursByUser(currUser, fromDate, toDate); if (presHours.Count() < displayPeriod.NumOfDays) { fromDate = timeSheetManager.GetFirstPresenceHour().Date; toDate = fromDate.AddDays(displayPeriod.NumOfDays); presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate); } result = TimeSheetAssembler.ToJsonsForRegister(presHours, workHours); } return(result); }
public async Task <IActionResult> GetPreviousPeriodConfirm(string ver, string type, Guid?userId, DateTime date) { UserManager userManager = new UserManager(this._uow); TimeSheetManager timeSheetManager = new TimeSheetManager(this._uow); DisplayPeriodManager displayPeriodMnager = new DisplayPeriodManager(this._uow); //SyncWithPWA(uow); User currUser = new UserHelper().GetCurrent(this._uow, this.UserName); DisplayPeriod displayPeriod = displayPeriodMnager.GetDisplayPeriod(currUser); DateTime fromDate; DateTime toDate; DateTime dt; if (type == "previous") { dt = date.AddDays(-1); fromDate = dt.AddDays(-displayPeriod.NumOfDays); toDate = dt; } else { dt = date.AddDays(1); fromDate = dt; toDate = dt.AddDays(displayPeriod.NumOfDays); } if (displayPeriod.IsWeekly) { fromDate = dt.StartOfWeek(DayOfWeek.Saturday); toDate = dt.EndOfWeek(DayOfWeek.Friday); } else { IEnumerable <PresenceHour> presHours = timeSheetManager.GetPresHoursByUser(currUser, fromDate, toDate); if (presHours.Count() < displayPeriod.NumOfDays) { fromDate = timeSheetManager.GetFirstPresenceHour().Date; toDate = fromDate.AddDays(displayPeriod.NumOfDays); } } return(await GetTimeSheet(ver, userId, fromDate, toDate)); }