public void DeleteSuggestion(Int64 suggestionId) { var temp = _suggestionRepository.Get(suggestionId); if (temp != null) { _suggestionRepository.Remove(temp); _suggestionRepository.UnitOfWork.Commit(); } }
public ActionResult <Suggestion> GetSuggestion([FromRoute] int id) { Logger.Info(this, $"Suggestion with id {id} is being retrieved"); Suggestion suggestion = _suggestionRepository.Get(id); if (suggestion == null) { return(NotFound()); } return(Ok(suggestion)); }
public async Task <Suggestion> Handle(VoteToASuggestionCommand voteToASuggestionCommand, CancellationToken cancellationToken = default) { var validationContext = new VoteToASuggestionValidationContext(voteToASuggestionCommand, _repository); _voteValidator.Validate(validationContext); var suggestion = _repository.Get(voteToASuggestionCommand.SuggestionId); var suggestionVote = _repository.GetUserVoteOrDefault(suggestion, voteToASuggestionCommand.UserId); var suggestionVoteExists = suggestionVote != null; if (suggestionVoteExists) { _repository.RemoveVote(suggestion, suggestionVote); } else { suggestionVote = _mapper.Map <SuggestionVote>(voteToASuggestionCommand); _repository.AddVote(suggestion, suggestionVote); } await _dbContext.SaveChangesAsync(); return(suggestion); }