public IActionResult UpdateVoting(Guid id, [FromBody] Voting voting) { if (voting.IsObjectNull()) { _logger.LogError("Voting object sent from client is null."); return(BadRequest("Voting object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid voting object sent from client."); return(BadRequest("Invalid model object")); } var dbVoting = _repository.Voting.GetVotingById(id); if (dbVoting.IsEmptyObject()) { _logger.LogError($"Voting with id: {id}, hasn't been found in db."); return(NotFound()); } _repository.Voting.UpdateVoting(dbVoting, voting); _repository.Save(); return(NoContent()); }
public IActionResult CreateVoting([FromBody] Voting voting) { if (voting.IsObjectNull()) { _logger.LogError("Voting object sent from client is null."); return(BadRequest("Voting object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid voting object sent from client."); return(BadRequest("Invalid model object")); } _repository.Voting.CreateVoting(voting); _repository.Save(); return(CreatedAtRoute("VotingById", new { id = voting.Id }, voting)); }