public async Task <IActionResult> Post([FromBody] AlbumToCreateDto albumDto) { if (!ModelState.IsValid) { return(BadRequest()); } //mapping dto to entity var album = _mapper.Map <Album>(albumDto); _albumRepo.Add(album); await _albumRepo.SaveChangesAsync(); var mappedAlbum = _mapper.Map <AlbumDto>(album); return(Ok(_albumLinkService.CreateLinks(mappedAlbum))); }
public async Task <IActionResult> Update(int id, [FromBody] AlbumToCreateDto albumDto) { if (!ModelState.IsValid) { return(BadRequest()); } var album = _mapper.Map <Album>(albumDto); _albumRepo.Update(id, album); await _albumRepo.SaveChangesAsync(); var updatedAlbum = await _albumRepo.GetByIdAsync(id); var mappedUpdatedAlbum = _mapper.Map <AlbumDto>(updatedAlbum); return(Ok(_albumLinkService.CreateLinks(mappedUpdatedAlbum))); }