public ActionResult <FavoriteReadDto> CreateFavorite(FavoriteUpdateCreateBaseDto favoriteUpdateCreate) { var favoriteModel = _mapper.Map<Favorites>(favoriteUpdateCreate); if(_validate.GetAccountById(favoriteModel.AccountId) == null) { ModelState.AddModelError("accountId", $"The account with key: {favoriteModel.AccountId}, does not exist"); return ValidationProblem(); } _repository.CreateFavorite(favoriteModel); _repository.SaveChanges(); var favoriteReadDto = _mapper.Map<FavoriteReadDto>(favoriteModel); return CreatedAtAction(nameof(CreateFavorite), new {id = favoriteReadDto.Id}, favoriteReadDto); }
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()); }