public ActionResult Create(Season season) { if (ModelState.IsValid) { Season InsertedSeason = DeactivateOtherSeasons(season); Unit.SeasonRepository.Insert(InsertedSeason); Unit.Save(); return RedirectToAction("Index"); } return View(season); }
public ActionResult Edit(Season season) { if (ModelState.IsValid) { Season updatedSeason = DeactivateOtherSeasons(season); Unit.SeasonRepository.Update(updatedSeason); Unit.Save(); if (Session["CurrentSeason"] != null) { Session.Remove("CurrentSeason"); } return RedirectToAction("Index"); } return View(season); }
/// <summary> /// For all other seasons when current is activ, set active to false and archive to true. /// Checking if only one season is active. /// </summary> /// <param name="season">Refferee.Models.Season</param> /// <returns>Referee.Models.Season</returns> private Season DeactivateOtherSeasons(Season season) { if (season.Active) { var otherSeasons = Unit.SeasonRepository.Get(filter: s => s.Id != season.Id); if (otherSeasons != null) { foreach (Season other in otherSeasons) { other.Active = false; other.Archive = true; Unit.SeasonRepository.Update(other); } } if (season.Id != CurrentSeason.Id) { SetCurrentSeason(true); } season.Archive = false; } return season; }