public async Task <ActionResult <AlbumDto> > AddAlbumForUser(AlbumCreationDto album) { bool isUserExist = await _albumRequestHandler.AlbumUserExist(album.userId); if (!isUserExist) { return(NotFound()); } var albumEntity = _mapper.Map <Album>(album); _albumRequestHandler.AddAlbum(albumEntity); var albumToReturn = _mapper.Map <AlbumDto>(albumEntity); return(CreatedAtRoute("GetAlbumByUserId", new { userId = albumToReturn.userId, id = albumToReturn.id, }, albumToReturn)); }
public ActionResult <AlbumDto> PostAlbum(Guid bandId, AlbumCreationDto creationDto) { if (!_bandAlbumRepository.BandExists(bandId)) { return(StatusCode(StatusCodes.Status404NotFound, new { error = "Band does not exist " })); } if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status400BadRequest, ModelState)); } var album = _mapper.Map <Album>(creationDto); _bandAlbumRepository.AddAlbum(bandId, album); _bandAlbumRepository.Save(); var albumDto = _mapper.Map <AlbumDto>(album); return(CreatedAtRoute("GetAlbumForBand", new { bandId, albumId = albumDto.BandId }, albumDto)); }