public ActionResult UpdateFavorite(Guid id, FavoriteUpdateCreateBaseDto favoriteUpdateDto) { if (!Request.Headers.ContainsKey("token")) { return Unauthorized(); } var auth = Request.Headers["token"]; var accountModel = _validate.GetAccountByToken(auth); if (accountModel == null) { return Unauthorized(); } var favoriteModelFromRepo = _repository.GetFavoiteById(id, accountModel.Id); if(favoriteModelFromRepo == null) { return NotFound(); } _mapper.Map(favoriteUpdateDto, favoriteModelFromRepo); _repository.UpdateFavorite(favoriteModelFromRepo); _repository.SaveChanges(); return NoContent(); }
public IActionResult PutFavorite(int id, Favorite favorite) { if (id != favorite.Id) { _logger.LogWarning($"Route value id: {id} does not match favorite id: {favorite.Id}"); return(BadRequest()); } if (!FavoriteExists(id)) { _logger.LogWarning($"Favorite with id: {id} does not exist."); return(NotFound()); } _favoriteRepo.UpdateFavorite(favorite); _favoriteRepo.SaveChanges(); _logger.LogInformation($"Favorite with id: {id} has been updated."); return(NoContent()); }