public TimeSchedules UpdateWokingInterval(int userId, int scheduleId, DayOfWeek startDay, TimeSpan startTime, DayOfWeek endDay, TimeSpan endTime) { Users user = GetUserById(userId); if (user == null) { throw new NoEntryFoundException(userId, typeof(Users).Name); } List <TimeSchedules> userSchedules = user.TheTimeScheduleForThisUser; TimeSchedules existing = userSchedules.Where(x => x.Id == scheduleId).SingleOrDefault(); if (existing == null) { throw new NoEntryFoundException(scheduleId, userId, typeof(TimeSchedules).Name); } existing.StartDay = startDay; existing.StartTime = startTime; existing.EndDay = endDay; existing.EndTime = endTime; List <TimeSchedules> overlapping = GetOverlappedSchedule(existing, userSchedules); if (overlapping.Count == 0) { TimeScheduleRepository.Update(existing); return(existing); } TimeSchedules newSchedule = SolveOverlappedSchedules(existing, overlapping); existing.StartDay = newSchedule.StartDay; existing.StartTime = newSchedule.StartTime; existing.EndDay = newSchedule.EndDay; existing.EndTime = newSchedule.EndTime; TimeScheduleRepository.Update(existing); foreach (var sch in overlapping) { TimeScheduleRepository.Remove(sch); } return(existing); }
public ActionResult EditTimeSchedule(TimeSchedule timeSchedule) { timeScheduleRepository.Update(timeSchedule); return(RedirectToAction("ViewTimeSchedule", "TimeSchedule", new { id = timeSchedule.Id })); }