public ActionResult SaveSchedule(OneWeekSchedule schedule) { _context.OneWeekSchedules.Add(schedule); _context.SaveChanges(); var viewModel = new OneWeekSchedule() { Employees = _context.Employees.ToList(), Week = schedule.Week, Positions = _context.Positions.ToList(), ScheduleName = schedule.ScheduleName, ShiftLengths = _context.ShiftLengths.ToList(), ShiftStartTimes = _context.ShiftStartTimes.ToList() }; return(View("DisplaySchedule", viewModel)); }
public ActionResult AutoGenerateSchedule(OneWeekSchedule schedule) { Random ran = new Random(); var week = schedule.Week.ToList(); var shiftStartTimes = _context.ShiftStartTimes.ToList(); var shiftLengths = _context.ShiftLengths.ToList(); var employees = _context.Employees.ToList(); var positions = _context.Positions.ToList(); for (int i = 0; i < week.Count; i++) { for (int j = 0; j < week[i].Shifts.Count; j++) { if (week[i].Shifts[j].ShiftStartTime.ShiftStartTime == 0) { if (ran.Next(10) < 7) { week[i].Shifts[j].ShiftStartTime = shiftStartTimes[ran.Next(shiftStartTimes.Count())]; } else { week[i].Shifts[j].ShiftStartTime.ShiftStartTime = 0; } } if (week[i].Shifts[j].ShiftLength.Shift == 0 && week[i].Shifts[j].ShiftStartTime.ShiftStartTime != 0) { if (week[i].Shifts[j].ShiftStartTime.ShiftStartTime + 8 <= 23) { week[i].Shifts[j].ShiftLength.Shift = 8; } else { week[i].Shifts[j].ShiftLength.Shift = 23 - week[i].Shifts[j].ShiftStartTime.ShiftStartTime; } } } } schedule.ShiftLengths = shiftLengths; schedule.ShiftStartTimes = shiftStartTimes; schedule.Employees = employees; schedule.Week = week; schedule.Positions = positions; return(View("ScheduleStepTwo", schedule)); }
public ActionResult GenerateSchedule() { var employees = _context.Employees.ToList(); var shiftLengths = _context.ShiftLengths.ToList(); var shiftStartTimes = _context.ShiftStartTimes.ToList(); var positions = _context.Positions.ToList(); var week = new List <Models.Day>(); for (int i = 0; i < 8; i++) { week.Add(null); } var viewModel = new OneWeekSchedule() { Employees = employees, ShiftLengths = shiftLengths, ShiftStartTimes = shiftStartTimes, Positions = positions, Week = week }; return(View(viewModel)); }