Пример #1
0
 public static Album ToDb(this Common.Album album)
 {
     return(new Album()
     {
         Id = album.Id,
         Name = album.Name,
         ReleaseDate = album.ReleaseDate
     });
 }
Пример #2
0
        public static Common.Album Create(Common.Album album)
        {
            using (var entities = new AlbumsCatalogueEntities())
            {
                var dbAlbum  = album.ToDb();
                var inserted = entities.Albums.Add(dbAlbum);
                entities.SaveChanges();

                return(inserted.ToCommon());
            }
        }
Пример #3
0
        public static Common.Album Update(Common.Album album)
        {
            using (var entities = new AlbumsCatalogueEntities())
            {
                var existing = entities.Albums.FirstOrDefault(x => x.Id == album.Id);
                existing.Name        = album.Name;
                existing.ReleaseDate = album.ReleaseDate;

                entities.SaveChanges();
                return(existing.ToCommon());
            }
        }