Example #1
0
        public ActionResult Create(Season season)
        {
            if (ModelState.IsValid)
            {
                Season InsertedSeason = DeactivateOtherSeasons(season);
                Unit.SeasonRepository.Insert(InsertedSeason);
                Unit.Save();
                return RedirectToAction("Index");
            }

            return View(season);
        }
Example #2
0
 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);
 }
Example #3
0
 /// <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;
 }