public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band) { var bandEntity = _mapper.Map <entities.Band>(band); _bandAlbumResponsitory.AddBand(bandEntity); _bandAlbumResponsitory.Save(); var bandToReturn = _mapper.Map <BandDto>(bandEntity); return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn)); }
public ActionResult <IEnumerable <BandDto> > CreateBandCollection([FromBody] IEnumerable <BandForCreatingDto> bandCollection) { var bandEntities = _mapper.Map <IEnumerable <entities.Band> >(bandCollection); foreach (var band in bandEntities) { _bandAlbumResponsitory.AddBand(band); } _bandAlbumResponsitory.Save(); var bandCollectionToReturn = _mapper.Map <IEnumerable <BandDto> >(bandEntities); var IdsString = string.Join(",", bandCollectionToReturn.Select(a => a.Id)); return(CreatedAtRoute("GetBandCollection", new { ids = IdsString }, bandCollectionToReturn)); }
public ActionResult <AlbumDto> CreateAlbumForBand(Guid bandId, [FromBody] AlbumCreatingDto album) { if (!_bandAlbumResponsitory.BandExists(bandId)) { return(NotFound()); } var albumEntity = _mapper.Map <entities.Album>(album); _bandAlbumResponsitory.AddAlbum(bandId, albumEntity); _bandAlbumResponsitory.Save(); var albumToReturn = _mapper.Map <AlbumDto>(albumEntity); return(CreatedAtRoute("GetAlbumForBand", new { bandId = bandId, albumId = albumToReturn.Id }, albumToReturn)); }