示例#1
0
        public async Task <ArtworkResponse> UpdateArtworkAsync(int id, Artwork artwork)
        {
            Artwork existingArtwork = await artworkRepository.FindByIdAsync(id);

            if (existingArtwork == null)
            {
                return(new ArtworkResponse("Artwork does not exist"));
            }

            existingArtwork.Name        = artwork.Name;
            existingArtwork.Description = artwork.Description;
            existingArtwork.ImageUrl    = artwork.ImageUrl;

            try
            {
                artworkRepository.Update(existingArtwork);
                await unitOfWork.CompleteAsync();

                return(new ArtworkResponse(existingArtwork));
            }
            catch (Exception ex)
            {
                return(new ArtworkResponse($"An error occured while updating artwork {ex.Message}"));
            }
        }
示例#2
0
 public IActionResult PutArtwork(int id, Artwork artwork)
 {
     if (id != artwork.Id)
     {
         return(BadRequest());
     }
     _artworkRepository.Update(artwork);
     _artworkRepository.SaveChanges();
     return(NoContent());
 }
示例#3
0
 public void EditArtwork(Artwork artwork)
 {
     _artworkrepository.Update(artwork);
     SaveArtwork();
 }