public ActionResult CreatePrizes(CreatePrizesBindingModel prizesModel, int contestId, int numOfWinnersRequired, int leftForAdding) { if (prizesModel != null && this.ModelState.IsValid) { var prize = new Prize() { ContestId = contestId, PrizeName = prizesModel.PrizeName, Position = leftForAdding }; this.Data.Prizes.Add(prize); this.Data.SaveChanges(); } int numOfWinnersInDb = this.Data.Prizes.All().Where(p => p.ContestId == contestId).Count(); if (numOfWinnersInDb < numOfWinnersRequired) { //If all winners prizes are'nt added to DB leftForAdding = numOfWinnersRequired - numOfWinnersInDb; this.ViewBag.leftForAdding = leftForAdding; return(this.RedirectToAction("CreatePrizes", "Contest", new { contestId = contestId, numOfWinnersRequired = numOfWinnersRequired, leftForAdding = leftForAdding })); } else { //If all winners prizes are added to DB var currentContest = this.Data.Contests.All().FirstOrDefault(c => c.Id == contestId); currentContest.Flag = Flag.Active; this.Data.SaveChanges(); var html = HttpContext.Server.HtmlEncode(currentContest.Name); SendContestCreatedNotification(string.Format("New contest \"{0}\" has been created.", html)); return(this.RedirectToAction("Details", "Contest", new { id = contestId })); } }
public ActionResult CreatePrizes(CreatePrizesBindingModel prizesModel, int contestId, int numOfWinnersRequired, int leftForAdding) { if (prizesModel != null && this.ModelState.IsValid) { var prize = new Prize() { ContestId = contestId, PrizeName = prizesModel.PrizeName, Position = leftForAdding }; this.Data.Prizes.Add(prize); this.Data.SaveChanges(); } int numOfWinnersInDb = this.Data.Prizes.All().Where(p => p.ContestId == contestId).Count(); if (numOfWinnersInDb < numOfWinnersRequired) { //If all winners prizes are'nt added to DB leftForAdding = numOfWinnersRequired - numOfWinnersInDb; this.ViewBag.leftForAdding = leftForAdding; return this.RedirectToAction("CreatePrizes", "Contest", new { contestId = contestId, numOfWinnersRequired = numOfWinnersRequired, leftForAdding = leftForAdding }); } else { //If all winners prizes are added to DB var currentContest = this.Data.Contests.All().FirstOrDefault(c => c.Id == contestId); currentContest.Flag = Flag.Active; this.Data.SaveChanges(); var html = HttpContext.Server.HtmlEncode(currentContest.Name); SendContestCreatedNotification(string.Format("New contest \"{0}\" has been created.", html)); return this.RedirectToAction("Details", "Contest", new { id = contestId }); } }