public static Album ToDb(this Common.Album album) { return(new Album() { Id = album.Id, Name = album.Name, ReleaseDate = album.ReleaseDate }); }
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()); } }
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()); } }