public PartialViewResult UpdatePoll(UpdatePollViewModel updatePollViewModel) { using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { try { // Fist need to check this user hasn't voted already and is trying to fudge the system if(!_pollVoteService.HasUserVotedAlready(updatePollViewModel.AnswerId, LoggedOnReadOnlyUser.Id)) { var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id); // Get the answer var pollAnswer = _pollAnswerService.Get(updatePollViewModel.AnswerId); // create a new vote var pollVote = new PollVote { PollAnswer = pollAnswer, User = loggedOnUser }; // Add it _pollVoteService.Add(pollVote); // Update the context so the changes are reflected in the viewmodel below unitOfWork.SaveChanges(); } // Create the view model and get ready return the poll partial view var poll = _pollService.Get(updatePollViewModel.PollId); var votes = poll.PollAnswers.SelectMany(x => x.PollVotes).ToList(); var alreadyVoted = (votes.Count(x => x.User.Id == LoggedOnReadOnlyUser.Id) > 0); var viewModel = new PollViewModel { Poll = poll, TotalVotesInPoll = votes.Count(), UserHasAlreadyVoted = alreadyVoted }; // Commit the transaction unitOfWork.Commit(); return PartialView("_Poll", viewModel); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } }
public void Delete(PollVote pollVote) { _context.PollVote.Remove(pollVote); }
public PollVote Add(PollVote pollVote) { return _context.PollVote.Add(pollVote); }
public void Delete(PollVote pollVote) { _pollVoteRepository.Delete(pollVote); }
public PollVote Add(PollVote pollVote) { return _pollVoteRepository.Add(pollVote); }