public ActionResult Create(ContestAdministrationViewModel model) { if (!this.IsValidContest(model)) { return(this.View(model)); } if (model != null && this.ModelState.IsValid) { var contest = model.GetEntityModel(); model.SubmisstionTypes.ForEach(s => { if (s.IsChecked) { var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id); contest.SubmissionTypes.Add(submission); } }); this.Data.Contests.Add(contest); this.Data.SaveChanges(); this.TempData.Add(GlobalConstants.InfoMessage, Resource.Contest_added); return(this.RedirectToAction(GlobalConstants.Index)); } return(this.View(model)); }
public ActionResult Create(ContestAdministrationViewModel model) { if (model?.CategoryId == null || !this.CheckIfUserHasContestCategoryPermissions(model.CategoryId.Value)) { return(this.RedirectToContestsAdminPanelWithNoPrivilegesMessage()); } this.ValidateContest(model); if (!this.ModelState.IsValid) { this.PrepareViewBagData(); return(this.View(model)); } var contest = model.GetEntityModel(); this.AddProblemGroupsToContest(contest, model.ProblemGroupsCount); this.AddIpsToContest(contest, model.AllowedIps); this.contestsData.Add(contest); this.TempData.Add(GlobalConstants.InfoMessage, Resource.Contest_added); return(this.RedirectToAction <ContestsController>(c => c.Index())); }
public ActionResult Edit(ContestAdministrationViewModel model) { if (model.Id == null || !this.CheckIfUserHasContestPermissions(model.Id.Value)) { return(this.RedirectToContestsAdminPanelWithNoPrivilegesMessage()); } this.ValidateContest(model); if (!this.ModelState.IsValid) { this.PrepareViewBagData(model.Id); return(this.View(model)); } var contest = this.contestsData.GetById(model.Id.Value); if (contest == null) { this.TempData.Add(GlobalConstants.DangerMessage, Resource.Contest_not_found); return(this.RedirectToAction <ContestsController>(c => c.Index())); } var originalContestPassword = contest.ContestPassword; var originalPracticePassword = contest.PracticePassword; if (contest.IsOnline && contest.IsActive && (contest.Duration != model.Duration || (int)contest.Type != model.Type)) { this.TempData.AddDangerMessage(Resource.Active_contest_cannot_edit_duration_type); this.RedirectToAction <ContestsController>(c => c.Index()); } contest = model.GetEntityModel(contest); if (contest.IsOnline && contest.ProblemGroups.Count == 0) { this.AddProblemGroupsToContest(contest, model.ProblemGroupsCount); } if (!contest.IsOnline && contest.Duration != null) { contest.Duration = null; } contest.AllowedIps.Clear(); this.AddIpsToContest(contest, model.AllowedIps); this.contestsData.Update(contest); this.InvalidateParticipants(originalContestPassword, originalPracticePassword, contest); this.TempData.Add(GlobalConstants.InfoMessage, Resource.Contest_edited); return(this.RedirectToAction <ContestsController>(c => c.Index())); }
public ActionResult Edit(ContestAdministrationViewModel model) { if (model.Id == null || !this.CheckIfUserHasContestPermissions(model.Id.Value)) { this.TempData[GlobalConstants.DangerMessage] = "Нямате привилегиите за това действие"; return(this.RedirectToAction("Index", "Contests", new { area = "Administration" })); } if (!this.IsValidContest(model)) { return(this.View(model)); } if (this.ModelState.IsValid) { var contest = this.Data.Contests.All().FirstOrDefault(c => c.Id == model.Id); if (contest == null) { this.TempData.Add(GlobalConstants.DangerMessage, Resource.Contest_not_found); return(this.RedirectToAction(GlobalConstants.Index)); } contest = model.GetEntityModel(contest); contest.SubmissionTypes.Clear(); model.SubmissionTypes.ForEach(s => { if (s.IsChecked) { var submission = this.Data.SubmissionTypes.All().FirstOrDefault(t => t.Id == s.Id); contest.SubmissionTypes.Add(submission); } }); contest.AllowedIps.Clear(); this.AddIpsToContest(contest, model.AllowedIps); this.Data.Contests.Update(contest); this.Data.SaveChanges(); this.TempData.Add(GlobalConstants.InfoMessage, Resource.Contest_edited); return(this.RedirectToAction(GlobalConstants.Index)); } this.PrepareViewBagData(); return(this.View(model)); }
public ActionResult Edit(ContestAdministrationViewModel model) { if (model.Id == null || !this.CheckIfUserHasContestPermissions(model.Id.Value)) { this.TempData[GlobalConstants.DangerMessage] = GlobalConstants.NoPrivilegesMessage; return(this.RedirectToAction <ContestsController>(c => c.Index())); } this.ValidateContest(model); if (!this.ModelState.IsValid) { this.PrepareViewBagData(model.Id); return(this.View(model)); } var contest = this.Data.Contests.All().FirstOrDefault(c => c.Id == model.Id); if (contest == null) { this.TempData.Add(GlobalConstants.DangerMessage, Resource.Contest_not_found); return(this.RedirectToAction <ContestsController>(c => c.Index())); } contest = model.GetEntityModel(contest); if (contest.IsOnline && contest.IsActive && (contest.Duration != model.Duration || contest.NumberOfProblemGroups != model.NumberOfProblemGroups || (int)contest.Type != model.Type)) { this.TempData.AddDangerMessage(Resource.Active_contest_cannot_edit_duration_type_problem_groups); this.RedirectToAction <ContestsController>(c => c.Index()); } contest.AllowedIps.Clear(); this.AddIpsToContest(contest, model.AllowedIps); this.Data.Contests.Update(contest); this.Data.SaveChanges(); this.TempData.Add(GlobalConstants.InfoMessage, Resource.Contest_edited); return(this.RedirectToAction <ContestsController>(c => c.Index())); }