public ActionResult Delete(int id, User u) { Web.ViewModel.UserCreateViewModel uc = new Web.ViewModel.UserCreateViewModel(); uc.user = _UserRepository.GetUserById(id); if (uc.user.AssignedRoleId == 3) { // if its a SA , then delete the number of available SA from the timeslot table . var timeslots = _timeSlotRepository.TimeSlots; // get the timeslots Threshold threshold = new Threshold(); threshold = _ThresholdRepository.Thresholds.First(); foreach (var timeslot in timeslots) { timeslot.Num_Available_SA = timeslot.Num_Available_SA - 1; timeslot.Title = timeslot.Num_Available_SA; if (timeslot.Num_Available_SA > threshold.Upper_Calendar) { timeslot.Color = "green"; } else if (timeslot.Num_Available_SA >= threshold.Lower_Calendar && timeslot.Num_Available_SA <= threshold.Upper_Calendar) { timeslot.Color = "yellow"; } else { timeslot.Color = "red"; } _timeSlotRepository.SaveTimeSlot(timeslot); } // whenever a SA is deleted , the calendar events of the SA should also be deleted . IEnumerable <CalendarEvent> events = new List <CalendarEvent>(); events = _eventsRepository.GetEventsByUserId(id); foreach (var e in events) { _eventsRepository.DeleteCalendarEvent(e); } } _UserRepository.DeleteUser(id); return(View("Deleted")); }