public ActionResult Activate(int id) { Election election = db.Elections.Find(id); if (election == null) { return(HttpNotFound()); } if (!ElectionLifecycleInfo.CanActivate(election)) { // No idea how we got here... History? return(RedirectToAction("Details", new { id })); } if (Request.HttpMethod.ToUpper() != "POST") { // Just show the template return(View(election)); } AntiForgery.Validate(); ChangeStateByUserAndRecord(election, ElectionState.PreNominations); db.SaveChanges(); BackgroundJob.Enqueue <SynchronizeDelayedJobsJob>(job => job.Execute(election.Id)); BackgroundJob.Enqueue(() => GenerateEligibilityEntries.Execute(election.Id, JobCancellationToken.Null)); return(RedirectToAction("Details", new { id })); }
public ActionResult Details(int id) { Election election = db.Elections.Find(id); if (election == null) { return(HttpNotFound()); } DetailsData data = new DetailsData { Common = election, NomineeEntries = new NomineeFetcher(new TimetableUserRepository()).Fetch(election.Positions) }; if (election.Type == ElectionType.StudentCouncil) { data.CouncilElectionData = db.CouncilElectionData .First(councilData => councilData.ElectionId == id); } // ReSharper disable once SwitchStatementMissingSomeCases switch (election.State) { case ElectionState.Disabled: { DetailsData.Action action = new DetailsData.Action() { Title = "Activate", Url = Url.Action("Activate", new { id }), CssType = "success" }; SimpleValidationResult validationResult = ElectionLifecycleInfo.CanActivate(election); if (!validationResult.IsNoErrors()) { action.Enabled = false; action.Tooltip = validationResult.Violations[0].HumanError; } else { action.Enabled = true; } data.Actions.Add(action); break; } case ElectionState.PreNominations: { DetailsData.Action action = new DetailsData.Action() { Title = "Deactivate", Url = Url.Action("Deactivate", new { id }), CssType = "warning", Enabled = true, Tooltip = "Go back to deactivated state" }; data.Actions.Add(action); break; } case ElectionState.Closed: { DetailsData.Action action = new DetailsData.Action() { Title = "Publish results", Url = Url.Action("PublishResults", new { id }), CssType = "success", Enabled = true }; data.Actions.Add(action); break; } } if (election.State == ElectionState.Aborted) { data.Actions.Add(new DetailsData.Action() { Title = "Remove from system", Enabled = true, Url = Url.Action("Delete", new { id }), CssType = "danger", }); } else { if (ElectionLifecycleInfo.CanEdit(election)) { data.Actions.Add(new DetailsData.Action() { Title = "Edit", Enabled = true, Url = Url.Action("Edit", new { id }), CssType = "primary" }); } // Should be last data.Actions.Add(new DetailsData.Action() { Title = "Abort", Enabled = true, Url = Url.Action("Abort", new { id }), CssType = "danger" }); } return(View(data)); }