Exemple #1
0
 public static Album MapAsNewEntity(this CreateAlbumRequestModel2 model, Artist artist)
 {
     return(new Album
     {
         Title = model.Title,
         Artist = artist
     });
 }
Exemple #2
0
        public async Task <ActionResult <AlbumModel> > Post(int artistId, CreateAlbumRequestModel2 model)
        {
            var artist = await this.context.Artist.FindAsync(artistId);

            if (artist == null)
            {
                return(this.NotFound());
            }

            var entity = model.MapAsNewEntity(artist);

            this.context.Album.Add(entity);
            await this.context.SaveChangesAsync();

            return(this.CreatedAtAction("Get", new { artistId = artistId, Title = entity.Title }, entity.MapAsModel()));
        }