public PartialViewResult GetVoters(VoteUpViewModel voteUpViewModel) { if (Request.IsAjaxRequest()) { var post = _postService.Get(voteUpViewModel.Post); var positiveVotes = post.Votes.Where(x => x.Amount > 0); var viewModel = new ShowVotersViewModel { Votes = positiveVotes.ToList() }; return PartialView(viewModel); } return null; }
public PartialViewResult GetVotes(VoteUpViewModel voteUpViewModel) { if (Request.IsAjaxRequest()) { var post = _postService.Get(voteUpViewModel.Post); var positiveVotes = post.Votes.Count(x => x.Amount > 0); var negativeVotes = post.Votes.Count(x => x.Amount <= 0); var viewModel = new ShowVotesViewModel { DownVotes = negativeVotes, UpVotes = positiveVotes}; return PartialView(viewModel); } return null; }
public void VoteUpPost(VoteUpViewModel voteUpViewModel) { if (Request.IsAjaxRequest()) { // Quick check to see if user is locked out, when logged in if (LoggedOnReadOnlyUser.IsLockedOut | !LoggedOnReadOnlyUser.IsApproved) { FormsAuthentication.SignOut(); throw new Exception(LocalizationService.GetResourceString("Errors.NoAccess")); } using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { // Get a db user var loggedOnUser = MembershipService.GetUser(LoggedOnReadOnlyUser.Id); // Firstly get the post var post = _postService.Get(voteUpViewModel.Post); // Now get the current user var voter = loggedOnUser; // Also get the user that wrote the post var postWriter = post.User; // Mark the post up or down MarkPostUpOrDown(post, postWriter, voter, PostType.Positive); try { unitOfWork.Commit(); } catch (Exception ex) { unitOfWork.Rollback(); LoggingService.Error(ex); throw new Exception(LocalizationService.GetResourceString("Errors.GenericMessage")); } } } }