private VMRosterModel CalculateRosterFields(VMRosterApplication vm, int _RotaAppID) { VAT_Shift shift = DDService.GetShift().Where(aa => aa.PShiftID == vm.ShiftID).First(); VMRosterModel _objmodel = new VMRosterModel(); try { int endPoint = 0; if (vm.RosterTypeID == 2) { endPoint = (vm.DateEnded.Value - vm.DateStarted.Value).Days + 1; } else if (vm.RosterTypeID == 3) { endPoint = 15; } else if (vm.RosterTypeID == 4) { endPoint = System.DateTime.DaysInMonth(vm.DateStarted.Value.Year, vm.DateEnded.Value.Month); } else if (vm.RosterTypeID == 4) { endPoint = 84; } _objmodel._RosterAttributes = new List <RosterAttributes>(); _objmodel.Criteria = ConvertCriteriaAbrvToFull("C"); _objmodel.RotaAppID = _RotaAppID; _objmodel.CriteriaValue = vm.CrewID; _objmodel.ShiftID = vm.ShiftID; _objmodel.StartDate = vm.DateStarted.Value; _objmodel.EndDate = vm.DateEnded.Value; _objmodel.NoOfDays = endPoint; _objmodel.CriteriaValueName = DDService.GetCrew().Where(aa => aa.PCrewID == vm.CrewID).First().CrewName; _objmodel.ShiftName = shift.ShiftName; DateTime _StartDate = vm.DateStarted.Value; for (int i = 1; i <= endPoint; i++) { string _day = _StartDate.Date.ToString("dddd"); string _date = _StartDate.Date.ToString("dd-MMM-yyyy"); string shiftStartTimeString = GetShiftStartTimeString(_StartDate.DayOfWeek, vm); TimeSpan shiftStartTime = ATAssistant.ConvertTime(shiftStartTimeString); int workMin = GetWorkMinutesForSpecificDates(_StartDate, vm); _objmodel._RosterAttributes.Add(new RosterAttributes { ID = i, DateString = _date, Day = _day, DutyDate = _StartDate.Date, DutyTimeString = shiftStartTimeString, DutyTime = shiftStartTime, WorkMin = workMin }); _StartDate = _StartDate.AddDays(1); } Expression <Func <RosterApplication, bool> > SpecificEntries = c => c.RotaAppID == _RotaAppID; RosterApplication rosterApp = RosterApplicationService.GetIndexSpecific(SpecificEntries).First(); rosterApp.DateEnded = _StartDate.AddDays(-1); RosterApplicationService.PostEdit(rosterApp); return(_objmodel); } catch (Exception ex) { return(_objmodel); } }
public VMRosterModel ContinueRoster(VMRosterContinue vm) { RosterApplication rosterApp = RosterApplicationService.GetEdit(vm.RotaAppID); Expression <Func <RosterDetail, bool> > SpecificEntries = c => c.RosterAppID == vm.RotaAppID; List <RosterDetail> rosterDetails = RosterDetailService.GetIndexSpecific(SpecificEntries); VMRosterApplication vmRotaApp = GetRosterApplication(rosterDetails, rosterApp, vm); rosterApp.DateEnded = vm.EndDate; RosterApplicationService.PostEdit(rosterApp); return(CalculateRosterFields(vmRotaApp, rosterApp.RotaAppID)); }
public ActionResult RosterEdit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RosterApplication rosterApp = RosterApplicationService.GetEdit((int)id); Expression <Func <RosterDetail, bool> > SpecificEntries = c => c.RosterAppID == id; List <RosterDetail> rosterDetails = RosterDetailService.GetIndexSpecific(SpecificEntries); return(View(CalculateRosterEditEntries(rosterApp, rosterDetails))); }
public ActionResult RosterDetail(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //RosterDetailsCustom _RosterDetails = new RosterDetailsCustom(); //_RosterDetails.RosterDetails = db.RosterDetails.Where(aa => aa.RosterAppID == id).ToList(); //RosterApp _RosterApp = new RosterApp(); //_RosterApp = db.RosterApps.First(aa => aa.RotaApplD == id); ////_RosterDetails //int CrewID = Convert.ToInt32(Request.Form["CrewList"].ToString()); Expression <Func <RosterDetail, bool> > SpecificEntries = c => c.RosterAppID == id; var rosterdetails = RosterDetailService.GetIndexSpecific(SpecificEntries); RosterApplication rosterApp = RosterApplicationService.GetEdit((int)id); VAT_RosterApplication vATrosterApp = VATRosterApplicationService.GetEdit((int)id); ViewBag.Header = "For Shift: " + vATrosterApp.ShiftName + ", Group: " + vATrosterApp.CrewName; return(View(CalculateRosterDetails(rosterdetails, rosterApp).OrderByDescending(aa => aa.DutyDate))); }
public VMRosterModel PostCreate1(VMRosterApplication vm, VMLoggedUser LoggedInUser) { //Saves the entry in the database table RosterApplication RosterApplication ra = new RosterApplication() { DateStarted = vm.DateStarted, DateEnded = vm.DateEnded, DateCreated = DateTime.Now, RosterCriteria = "C", CriteriaData = vm.CrewID, RotaTypeID = (byte)vm.RosterTypeID, Status = true, ShiftID = (byte)vm.ShiftID, UserID = LoggedInUser.PUserID }; RosterApplicationService.PostCreate(ra); return(CalculateRosterFields(vm, ra.RotaAppID)); }
public ActionResult Delete(VMRosterApplication obj) { RosterApplication RApp = new RosterApplication(); //User uid = new User(); RApp = RosterApplicationService.GetEdit(obj.RotaApplD); try { Expression <Func <RosterDetail, bool> > SpecificEntries = c => c.RosterAppID == obj.RotaApplD; List <RosterDetail> RAppDetail = RosterDetailService.GetIndexSpecific(SpecificEntries); foreach (var item in RAppDetail) { RosterDetailService.PostDelete(item); } } catch (Exception) { throw; } RosterApplicationService.PostDelete(RApp); return(RedirectToAction("Index")); }
private void SaveEditRosterEntries(List <RosterAttributes> rosters, int _RotaAppID) { RosterApplication rotaApp = RosterApplicationService.GetEdit(_RotaAppID); VAT_Shift shift = DDService.GetShift().Where(aa => aa.PShiftID == rotaApp.ShiftID).First(); foreach (var roster in rosters) { //if (isRosterValueChanged(roster, shift)) { RosterDetail rosterDetail = new RosterDetail(); rosterDetail.CriteriaValueDate = rotaApp.RosterCriteria.ToString() + rotaApp.CriteriaData.ToString() + roster.DutyDate.ToString("yyMMdd"); //rosterDetail.CompanyID = rotaApp.CompanyID; rosterDetail.OpenShift = shift.OpenShift; //rosterDetail.UserID = rotaApp.UserID; rosterDetail.RosterAppID = _RotaAppID; if (roster.WorkMin == 0) { rosterDetail.DutyCode = "R"; } else { rosterDetail.DutyCode = "D"; } if (roster.DutyTime == new TimeSpan(0, 0, 0)) { rosterDetail.OpenShift = true; } else { rosterDetail.OpenShift = false; } rosterDetail.DutyTime = roster.DutyTime; rosterDetail.WorkMin = (short)roster.WorkMin; rosterDetail.RosterDate = roster.DutyDate; RosterDetailService.PostCreate(rosterDetail); } } }
private VMRosterModel CalculateRosterEditEntries(RosterApplication rosterApp, List <RosterDetail> rosterDetails) { VAT_Shift shift = DDService.GetShift().Where(aa => aa.PShiftID == rosterApp.ShiftID).First(); VMRosterModel _objmodel = new VMRosterModel(); int i = 1; try { _objmodel._RosterAttributes = new List <RosterAttributes>(); DateTime _StartDate = (DateTime)rosterApp.DateStarted; _objmodel.RotaAppID = rosterApp.RotaAppID; _objmodel.ShiftName = shift.ShiftName; switch (rosterApp.RosterCriteria) { case "S": break; case "C": _objmodel.CriteriaValueName = DDService.GetCrew().Where(aa => aa.PCrewID == rosterApp.CriteriaData).First().CrewName; break; case "T": break; case "employee": break; } while (_StartDate <= rosterApp.DateEnded) { string _day = _StartDate.Date.ToString("dddd"); string _date = _StartDate.Date.ToString("dd-MMM-yyyy"); string _DTime = ""; TimeSpan _DutyTime = new TimeSpan(); int _WorkMin = 0; if (rosterDetails.Where(aa => aa.RosterDate == _StartDate).Count() > 0) { // from roster details RosterDetail rotaDetail = rosterDetails.First(aa => aa.RosterDate == _StartDate); _DTime = rotaDetail.DutyTime.Value.Hours.ToString("00") + rotaDetail.DutyTime.Value.Minutes.ToString("00"); _WorkMin = (int)rotaDetail.WorkMin; _DutyTime = (TimeSpan)rotaDetail.DutyTime; } else { //from shift _DTime = shift.StartTime.Hours.ToString("00") + shift.StartTime.Minutes.ToString("00"); _WorkMin = CalculateShiftWorkMins(_StartDate, shift); _DutyTime = shift.StartTime; } _objmodel._RosterAttributes.Add(new RosterAttributes { ID = i, DateString = _date, Day = _day, DutyDate = _StartDate.Date, DutyTimeString = _DTime, DutyTime = _DutyTime, WorkMin = _WorkMin }); _StartDate = _StartDate.AddDays(1); i++; } _objmodel.NoOfDays = i; return(_objmodel); } catch (Exception ex) { return(_objmodel); } }
private List <RosterDetailAttributes> CalculateRosterDetails(List <RosterDetail> rosterdetails, RosterApplication rosterApp) { //List<RosterDetailModel> rdm = new List<RosterDetailModel>(); List <RosterDetailAttributes> rda = new List <RosterDetailAttributes>(); //Shift shift = new Shift(); //shift = db.Shifts.First(aa => aa.ShiftID == rosterApp.ShiftID); DateTime currentDate = rosterApp.DateStarted.Value; List <RosterDetail> tempRotaDetails = new List <RosterDetail>(); while (currentDate <= rosterApp.DateEnded) { RosterDetailAttributes rdaS = new RosterDetailAttributes(); tempRotaDetails = rosterdetails.Where(aa => aa.RosterDate == currentDate).ToList(); if (tempRotaDetails.Count > 0) { rdaS.Changed = true; rdaS.Day = tempRotaDetails.FirstOrDefault().RosterDate.Value.ToString("dddd"); rdaS.DutyCode = tempRotaDetails.FirstOrDefault().DutyCode; rdaS.DutyDate = tempRotaDetails.FirstOrDefault().RosterDate.Value; rdaS.DutyTime = (TimeSpan)tempRotaDetails.FirstOrDefault().DutyTime; rdaS.WorkMin = (short)tempRotaDetails.FirstOrDefault().WorkMin; } else { //rdaS.Changed = false; //rdaS.Day = currentDate.ToString("dddd"); //int wrkMin = CalculateDutyCode(shift, currentDate); //if (wrkMin == 0) // rdaS.DutyCode = "R"; //else // rdaS.DutyCode = "D"; //rdaS.DutyDate = currentDate; //rdaS.DutyTime = shift.StartTime; //rdaS.WorkMin = wrkMin; } rda.Add(rdaS); currentDate = currentDate.AddDays(1); } return(rda); }
private VMRosterApplication GetRosterApplication(List <RosterDetail> rosterDetails, RosterApplication rosterApp, VMRosterContinue obj) { VMRosterApplication vm = new VMRosterApplication(); vm.DateEnded = obj.EndDate; vm.DateStarted = rosterApp.DateEnded.Value.AddDays(1); vm.CrewID = (int)rosterApp.CriteriaData; vm.RosterTypeID = (byte)rosterApp.RotaTypeID; vm.RotaApplD = rosterApp.RotaAppID; vm.ShiftID = (int)rosterApp.ShiftID; vm.FriMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Friday).First()); vm.FriStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Friday).First()); vm.SatMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Saturday).First()); vm.SatStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Saturday).First()); vm.SunMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Sunday).First()); vm.SunStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Sunday).First()); vm.MonMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Monday).First()); vm.MonStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Monday).First()); vm.TueMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Tuesday).First()); vm.TueStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Tuesday).First()); vm.WedMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Wednesday).First()); vm.WedStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Wednesday).First()); vm.ThruMin = GetWorkMinutes(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Thursday).First()); vm.ThruStartTime = GetShiftStartTime(rosterDetails.Where(aa => aa.RosterDate.Value.DayOfWeek == DayOfWeek.Thursday).First()); return(vm); }