public async Task<ActionResult<PostVoteResponseModel>> Post(PostVoteInputModel input) { string userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.votesService.SetVoteAsync(input.RecipeId, userId, input.Value); var averageVotes = this.votesService.GetAverageVotes(input.RecipeId); return new PostVoteResponseModel { AverageVote = averageVotes }; }
public async Task <IActionResult> Vote(PostVoteInputModel input) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.voteService.SetVoteAsync(input.DriverId, userId, input.Value); // var averageVote = this.voteService.GetAverageVote(input.DriverId); return(this.RedirectToAction("AllUserOrders", "Users")); }
public async Task <ActionResult <PostVoteViewModel> > Post(PostVoteInputModel input) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.votesService.SetVoteAsync(input.BlogId, userId, input.Value); var averageVotes = this.votesService.GetAverageVotes(input.BlogId); return(new PostVoteViewModel { AverageVote = averageVotes }); }
public async Task <ActionResult <PostVoteResponseModel> > Post(PostVoteInputModel input) { var userId = this.userManager.GetUserId(this.User); await this.postVotesService.VoteAsync(input.PostId, userId, input.IsUpVote); var upVotes = this.postVotesService.GetVote(input.PostId); var downVotes = this.postVotesService.GetDownVote(input.PostId); return(new PostVoteResponseModel { DownVotesCount = downVotes, UpVotesCount = upVotes }); }
public async Task <ActionResult <PostVoteResponseModel> > Post(PostVoteInputModel input) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; if (!this.votesService.HasVoted(userId, input.IssueId)) { await this.votesService.CreateAsync(userId, input.IssueId); } else { await this.votesService.DeleteAsync(userId, input.IssueId); } var viewModel = this.issuesService.GetById <PostVoteResponseModel>(input.IssueId); return(viewModel); }
public async Task <ActionResult <ResponseVoteModel> > Post([FromBody] PostVoteInputModel input) { if (this.User.Identity.IsAuthenticated) { if (await this.postsService.DoesPostExistAsync(input.PostId)) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var status = await this.votesService.PostVoteAsync(input.PostId, userId, input.IsUpvote); return(new ResponseVoteModel() { Status = status }); } return(this.NotFound()); } return(this.Unauthorized()); }
public async Task <ActionResult <PostVoteResponseModel> > Post(PostVoteInputModel input) { var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; var vote = this.votesRepository.All() .FirstOrDefault(x => x.ProductId == input.ProductId && x.UserId == userId); if (vote == null) { await this.votesService.SetVoteAsync(input.ProductId, userId, input.Value, input.IsProductRatedByUser); var averageVotes = this.votesService.GetAverageVotes(input.ProductId); return(new PostVoteResponseModel { AverageVote = averageVotes }); } else { return(this.RedirectToAction("Index", "Home")); } }
public async Task <ActionResult <PostVoteResponseModel> > Post(PostVoteInputModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var votedId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; var isValidVote = await this.votesService.SetVoteAsync(votedId, model.VotedForId, model.Value); var averageVote = this.votesService.GetAverageVotes(model.VotedForId); var votes = this.votesService.GetVotesCount(model.VotedForId); if (isValidVote) { return(new PostVoteResponseModel { AverageVote = averageVote, Votes = votes, }); } return(this.Unauthorized()); }