public IActionResult Complete(VoteModel voteModel) { var targetEvent = GetActiveEventById(voteModel.EventId); if (targetEvent == null) { return(View("NotFound")); } // get an uncompleted vote and its choices var vote = _context.Votes .Include(x => x.Choices) .FirstOrDefault(x => x.ID == voteModel.VoteId && !x.IsCompleted); // user has already voted, redirect to voting if (vote == null) { return(RedirectToAction("Index", new { id = voteModel.PublicToken.HasValue ? voteModel.EventId : voteModel.Token })); } foreach (var choiceModel in voteModel.Choices) { var choice = vote.Choices.FirstOrDefault(x => x.ID == choiceModel.Id); if (choice == null) { continue; } choice.OptionID = choiceModel.OptionId; } _context.SaveChanges(); // some question was not selected if (voteModel.Choices.Any(x => !x.OptionId.HasValue)) { return(RedirectToAction("Index", new { id = voteModel.PublicToken.HasValue ? voteModel.EventId : voteModel.Token, error = 1 })); } vote.IsCompleted = true; _context.SaveChanges(); return(RedirectToAction("Index", new { id = voteModel.PublicToken.HasValue ? voteModel.EventId : voteModel.Token })); }
public async Task <IActionResult> ActivateEvent(Guid eventId) { var target = await GetEventById(eventId); // NOTE: issue#8 on github // finished events may be re-activated if (CanActivate(target) || target.EndDate.HasValue) { target.StartDate = DateTime.UtcNow; target.EndDate = null; _context.SaveChanges(); } return(RedirectToAction("Details", "Event", new { eventId = target.ID })); }
public async Task <IActionResult> Edit(EventModel eventModel) { var target = await GetEventById(eventModel.EventId); // Event not found or invalid user if (target == null) { return(RedirectToAction("Index", "Dashboard")); } if (ModelState.IsValid) { if (target.IsPublic != eventModel.IsPublic) { target.IsPublic = eventModel.IsPublic; } if (target.ShowOverallWinner != eventModel.ShowOverallWinner) { target.ShowOverallWinner = eventModel.ShowOverallWinner; } if (target.Description != eventModel.Description) { target.Description = eventModel.Description; } if (target.Name != eventModel.EventName) { target.Name = eventModel.EventName; } _context.SaveChanges(); return(RedirectToAction("Edit", "Event", new { eventId = eventModel.EventId, section = "general" })); } ViewBag.Section = "general"; return(View("Edit", await InitEditEventModel(eventModel.EventId))); }