public Album CreateAlbum(string name, string description, bool isPublic, IEnumerable<Tag> tags, int categoryId) { var oldAlbum = UnitOfWork.Albums.Get(album => album.Name.Equals(name)); if (oldAlbum != null) throw new DataException("Album name already exists."); if (tags == null) { tags = new Tag[] { }; } var newAlbum = new AlbumEntity { CategoryId = categoryId, CreatedOn = DateTime.UtcNow, Description = description, IsPublic = isPublic, Name = name, Tags = tags.Select(tag => new TagEntity { Id = tag.Id }).ToList(), }; newAlbum = UnitOfWork.Albums.Add(newAlbum); UnitOfWork.Commit(); return newAlbum.ToModel(); }
public Album UpdateAlbumCategory(int albumId, int categoryId) { var oldAlbum = UnitOfWork.Albums.GetById(albumId); if (oldAlbum == null) throw new DataException("Album could not be retrieved."); var newAlbum = new AlbumEntity { CategoryId = categoryId }; newAlbum = UnitOfWork.Albums.Update(newAlbum); UnitOfWork.Commit(); return newAlbum.ToModel(); }