public IActionResult PutVote(int id, string author, int vote) { Poem poem = _poemRepository.GetById(id); if (vote == 0) { if (!poem.DownVoters.Contains(author)) { poem.AddDownvote(); poem.DownVoters.Add(author); if (poem.UpVoters.Contains(author)) { poem.RemoveUpvote(); poem.UpVoters.Remove(author); } } } else { if (!poem.UpVoters.Contains(author)) { poem.AddUpvote(); poem.UpVoters.Add(author); if (poem.DownVoters.Contains(author)) { poem.RemoveDownvote(); poem.DownVoters.Remove(author); } } } _poemRepository.Update(poem); _poemRepository.SaveChanges(); return(NoContent()); }
public IActionResult PutPoem(int id, Poem poem) { if (id != poem.Id) { return(BadRequest()); } _poemRepository.Update(poem); _poemRepository.SaveChanges(); return(NoContent()); }