public async Task <VoteDTO> EditVote(VoteEditDTO voteInfo, int tripId) { using (_unitOfWork) { Vote vote = await _unitOfWork.VoteRepository.FindByID(voteInfo.VoteId); if (vote.Positive != voteInfo.Positive) { Votable votable = await _unitOfWork.VotableRepository.FindByID(vote.VotableId); if (vote.Positive) { votable.NegativeVotes++; votable.PositiveVotes--; } else { votable.NegativeVotes--; votable.PositiveVotes++; } await _messageControllerService.NotifyOnTripChanges(tripId, "ChangeVotable", _mapper.Map <Votable, VotableDTO>(votable)); } vote.Positive = voteInfo.Positive; await _unitOfWork.Save(); return(_mapper.Map <Vote, VoteDTO>(vote)); } }
public async Task <ActionResult> CheckIfVoted(int votableId, int userId) { try { VoteEditDTO retValue = await _voteService.HaveIVotedFor(votableId, userId); if (retValue == null) { return(Ok(false)); } return(Ok(retValue)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult> ChangeVote(int tripId, [FromBody] VoteEditDTO voteInfo) { try { if (!await _editRightsService.HasEditRights(tripId)) { return(BadRequest(new JsonResult("You can't currently edit this trip."))); } VoteDTO retValue = await _voteService.EditVote(voteInfo, tripId); await _editRightsService.ProlongEditRights(tripId, _redisAppSettings.EditRightsProlongedTTL); if (retValue == null) { return(BadRequest(new JsonResult("Vote does not exist"))); } return(Ok(retValue)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }