public ActionResult Details(int id, CalendarDetailsViewModel model) { model.Calendar = _unitOfWork.CalendarRepository.GetById(id); if (ModelState.IsValid) { try { if (model.Season.FirstWeekDate.HasValue && model.Season.LastWeekDate.HasValue) { var calendarParser = new CalendarParser(_unitOfWork.TeamRepository); model.Season.Weeks = (ICollection<Week>)calendarParser.ParseWeeks(model.Calendar, model.Season.FirstWeekDate.Value, model.Season.LastWeekDate.Value); model.Calendar.Seasons.Add(model.Season); _unitOfWork.CalendarRepository.Update(model.Calendar); _unitOfWork.Save(); return RedirectToAction("Details", new { id }); } } catch (Exception e) { this.Logger.ErrorFormat(e.ToString()); ModelState.AddModelError("sql", "An error occured."); //TODO: add error message to resources } } return View(model); }
public ActionResult Details(int id) { var model = new CalendarDetailsViewModel() { Calendar = _unitOfWork.CalendarRepository.GetById(id), Season = new Season() }; return View("Details", model); }