public IActionResult UpdatePhotographer(Guid id, [FromBody] PhotographerForUpdateDto photographer) { if (photographer == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } if (!_magnumPhotosRepository.PhotographerExists(id)) { return(NotFound()); } var photographerFromRepo = _magnumPhotosRepository.GetPhotographer(id); if (photographerFromRepo == null) { var photographerToAdd = Mapper.Map <Photographer> (photographer); photographerToAdd.Id = id; _magnumPhotosRepository.AddPhotographer(photographerToAdd); if (!_magnumPhotosRepository.Save()) { throw new Exception($"Upserting photographer {id} failed on save."); } var photographerToReturn = Mapper.Map <Photographer> (photographerToAdd); return(CreatedAtRoute("GetPhotographer", new { id = photographerToReturn.Id }, photographerToReturn)); } Mapper.Map(photographer, photographerFromRepo); if (!_magnumPhotosRepository.Save()) { throw new Exception($"Updating photographer {id} failed on save."); } return(NoContent()); }
public IActionResult GetBooks(Guid photographerId) { if (!_magnumPhotosRepository.PhotographerExists(photographerId)) { return(NotFound()); } var booksFromRepo = _magnumPhotosRepository.GetBooks(photographerId); var books = Mapper.Map <IEnumerable <BookDto> > (booksFromRepo); books = books.Select(book => { book = CreateLinksForBook(book); return(book); }); var wrapper = new LinkedCollectionResourceWrapper <BookDto> (books); return(Ok(CreateLinksForBooks(wrapper))); }