public ActionResult DeleteShedule(DeleteSheduleViewModel model) { int cityId = (int)Session["City"]; if(ModelState.IsValid) { try { var bus = busRepository.Get(x => x.Number == model.Bus && x.CityId == cityId).First(); var stop = stopsRepository.Get(x => x.Name == model.Stop && x.CityId == cityId).First(); var endStop = stopsRepository.Get(x => x.Name == model.EndStop && x.CityId == cityId).First(); var timeTable = timeTablesRepository.Get(x => x.Bus.Id == bus.Id && x.Stop.Id == stop.Id && x.FinalStop.Id == endStop.Id).First(); var shedules = timeTable.Shedules.Where(x => x.Days.ToDescription() == model.Days); shedulesRepository.DeleteRange(shedules); TempData["Success"] = "Запись удалена"; } catch(Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex); ModelState.AddModelError("", "Ошибка при удалении записи. Повторите попытку позже"); } } var buses = timeTablesRepository.Get(x => x.Bus.CityId == cityId && x.Shedules.Count != 0) .Select(x => x.Bus.Number) .Distinct(); model.Bus = null; model.Buses = buses; model.Stop = null; model.EndStop = null; model.Days = null; return View(model); }
public ActionResult DeleteShedule() { int cityId = (int)Session["City"]; var buses = timeTablesRepository.Get(x => x.Bus.CityId == cityId && x.Shedules.Count != 0) .Select(x => x.Bus.Number) .Distinct(); DeleteSheduleViewModel model = new DeleteSheduleViewModel { Buses = buses}; return View(model); }