public IHttpActionResult Update(AlbumDataModel album) { if (album == null || album.Id == null) { return(this.BadRequest("You must provide album ID.")); } var existingAlbum = this.db.Albums.Find(album.Id); if (existingAlbum == null) { return(this.BadRequest("An album with the provided ID do not exist.")); } if (album.Title != null) { existingAlbum.Title = album.Title; } if (album.Producer != null) { existingAlbum.Producer = album.Producer; } if (album.Year != null) { existingAlbum.Year = album.Year; } this.db.SaveChanges(); return(this.Ok(existingAlbum)); }
public IHttpActionResult Update(AlbumDataModel album) { if (album == null || album.Id == null) { return this.BadRequest("You must provide album ID."); } var existingAlbum = this.db.Albums.Find(album.Id); if (existingAlbum == null) { return this.BadRequest("An album with the provided ID do not exist."); } if (album.Title != null) { existingAlbum.Title = album.Title; } if (album.Producer != null) { existingAlbum.Producer = album.Producer; } if (album.Year != null) { existingAlbum.Year = album.Year; } this.db.SaveChanges(); return this.Ok(existingAlbum); }
public static ICollection <AlbumViewModel> Map(AlbumDataModel dataAlbums) { ICollection <AlbumViewModel> albums = new List <AlbumViewModel>(); foreach (var dataAlbum in dataAlbums.AlbumDetails) { var album = new AlbumViewModel( 0, dataAlbum.Name, dataAlbum.Popularity ); foreach (var domainArtist in dataAlbum.Artists) { album.Artists.Add(new ArtistViewModel( 0, domainArtist.Name, domainArtist.FullDetailsLink, domainArtist.Uri ) ); } albums.Add(album); } return(albums); }
public IHttpActionResult Put(int id, [FromBody] AlbumDataModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var album = this.data.Albums.Find(id); if (album == null) { return(this.BadRequest("No such album can be found.")); } if (this.data.Producers.Find(model.ProducerId) == null) { return(this.BadRequest("No such producer can be found.")); } album.Name = model.Name; album.Year = model.Year; album.ProducerId = model.ProducerId; if (this.AddArtistsToAlbum(model.ArtistIds, album) == null || this.AddSongsToAlbum(model.SongIds, album) == null) { return(this.BadRequest("No such song/artist can be found.")); } this.data.Albums.Update(album); this.data.Savechanges(); return(this.Ok(album)); }
public IHttpActionResult Post([FromBody] AlbumDataModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } if (this.data.Producers.Find(model.ProducerId) == null) { return(this.BadRequest("No such producer can be found.")); } var album = new Album { Name = model.Name, ProducerId = model.ProducerId, Year = model.Year }; if (this.AddArtistsToAlbum(model.ArtistIds, album) == null || this.AddSongsToAlbum(model.SongIds, album) == null) { return(this.BadRequest("No such song/artist can be found.")); } this.data.Albums.Add(album); this.data.Savechanges(); return(this.Created(this.Url.ToString(), album)); }
public AlbumDataModel Transform() { var dataModel = new AlbumDataModel { AlbumId = this.AlbumId, AlbumName = this.AlbumName, Photos = this.Photos.Select(p => p.Transform()).ToList() }; return(dataModel); }
public static AlbumDataModel ModelToEntity(AlbumVM model) { AlbumDataModel entity = new AlbumDataModel(); entity.ID = model.id; entity.Name = model.Name; entity.DateCreated = model.DateCreated; entity.UserID = model.UserID; return(entity); }
public static AlbumVM EntityToModel(AlbumDataModel entity) { AlbumVM model = new AlbumVM(); model.id = entity.ID; model.Name = entity.Name; model.DateCreated = entity.DateCreated; model.UserID = entity.UserID; model.NoOfPhotos = entity.photos.Count; model.User = EntityToModel(entity.User); return(model); }
public IHttpActionResult Post([FromBody] AlbumDataModel albumModel) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var album = AlbumDataModel.FromModelToData(albumModel); this.Data.Albums.Add(album); this.Data.SaveChanges(); return(this.Created(this.Url.ToString(), album)); }
/// <summary> /// DBのモデルデータからアルバム情報を生成する /// </summary> /// <param name="album">アルバム情報</param> /// <param name="artwork">アートワーク情報</param> public AlbumInfo(AlbumDataModel album, AlbumArtworksDataModel artwork) { this.Key = album.Key; this.Id = album.Id; this.Name = album.Name; this.Artist = album.Artist; this.ArtworkId = album.ArtworkId; this.IsCompilation = album.IsCompilation ?? false; this.RegisteredAt = album.CreatedAt; this.UpdatedAt = album.UpdatedAt; this._isArtworkFound = album.ArtworkId != null; this.Playlist = new AlbumPlaylist(this); }
public IHttpActionResult Create(AlbumDataModel newAlbum) { if (newAlbum == null || newAlbum.Title == null) { return(this.BadRequest("You must proive album title.")); } var album = new Album { Title = newAlbum.Title, Producer = newAlbum.Producer, Year = newAlbum.Year }; this.db.Albums.Add(album); this.db.SaveChanges(); return(this.Ok(album)); }
public IHttpActionResult Create(AlbumDataModel newAlbum) { if (newAlbum == null || newAlbum.Title == null) { return this.BadRequest("You must proive album title."); } var album = new Album { Title = newAlbum.Title, Producer = newAlbum.Producer, Year = newAlbum.Year }; this.db.Albums.Add(album); this.db.SaveChanges(); return this.Ok(album); }
public bool AddOrUpdate(AlbumDataModel album) { try { using (var ctx = new MVCContext()) { var albumToUpdate = ctx.Albums.Where(g => g.ID == album.ID) .Include(g => g.photos) .Include(g => g.User) .FirstOrDefault(); if (albumToUpdate != null) { albumToUpdate.Name = album.Name; albumToUpdate.Description = album.Description; ctx.SaveChanges(); return(true); } else { var newAlbum = new AlbumDataModel(); newAlbum.UserID = album.UserID; newAlbum.User = album.User; newAlbum.Name = album.Name; newAlbum.Description = album.Description; newAlbum.DateCreated = DateTime.Now; ctx.Albums.Add(newAlbum); ctx.SaveChanges(); return(true); } } } catch (Exception e) { // handle exceptions } return(false); }
public IHttpActionResult Put(int id, [FromBody] AlbumDataModel albumModel) { if (!ModelState.IsValid) { return(this.BadRequest(ModelState)); } var album = this.Data.Albums.SearchFor(a => a.Id == id).FirstOrDefault(); if (album == null) { return(this.BadRequest("Invalid id")); } album.Title = string.IsNullOrEmpty(albumModel.Title) ? album.Title : albumModel.Title; album.Producer = string.IsNullOrEmpty(albumModel.Producer) ? album.Producer : albumModel.Producer; album.Year = albumModel.Year; this.Data.Albums.Update(album); this.Data.SaveChanges(); return(this.Ok()); }
public Album(AlbumDataModel Albumdata) { AlbumId = Albumdata.AlbumId; AlbumName = Albumdata.AlbumName; Photos = new List <Photo>(); }