public bool Create(string name, string link, decimal price, string albumId) { if (!context.Albums.Any(p => p.Id == albumId)) { return(false); } var track = new Track { Name = name, Link = link, Price = price, }; var trackAlbum = new AlbumTrack { Track = track, Album = context.Albums.SingleOrDefault(p => p.Id == albumId) }; context.AlbumTracks.Add(trackAlbum); context.SaveChanges(); return(true); }
private void PopulateDatabase(IRunesDbContext dbContext) { if (!dbContext.Albums.Any() && !dbContext.Tracks.Any()) { var album1 = new Album() { Artist = "The Offspring", Title = "Americana", Genre = MusicGenre.PunkRock, CoverArt = "http://c0000636.cdn2.cloudfiles.rackspacecloud.com/americana_cover_t1.jpg" }; var track1 = new Track() { Artist = album1.Artist, Title = "Pretty Fly (For a White Guy)", Genre = MusicGenre.PunkRock, Link = "https://www.youtube.com/embed/QtTR-_Klcq8", Price = 1.99M }; var track2 = new Track() { Artist = album1.Artist, Title = "Why Don't You GET A Job?", Genre = MusicGenre.Rock, Link = "https://www.youtube.com/embed/LH-i8IvYIcg", Price = 1.99M }; album1.Price += track1.Price + track2.Price; var album2 = new Album() { Artist = "Tchaikovsky", Title = "Greatest Hits", Genre = MusicGenre.Classical }; var track3 = new Track() { Artist = album2.Artist, Title = "Nocturne", Genre = MusicGenre.Classical, Link = "http://www.hochmuth.com/mp3/Tchaikovsky_Nocturne__orch.mp3", Price = 0.99M }; album2.Price += track3.Price; dbContext.Albums.Add(album1); dbContext.Albums.Add(album2); dbContext.Tracks.Add(track1); dbContext.Tracks.Add(track2); dbContext.Tracks.Add(track3); dbContext.SaveChanges(); album1.AlbumTracks.Add(new AlbumTrack() { AlbumId = album1.Id, TrackId = track1.Id }); album1.AlbumTracks.Add(new AlbumTrack() { AlbumId = album1.Id, TrackId = track2.Id }); album2.AlbumTracks.Add(new AlbumTrack() { AlbumId = album2.Id, TrackId = track3.Id }); dbContext.SaveChanges(); } }
public void Add(string name, string cover) { var album = new Album { Name = name, Cover = cover }; this.context.Albums.Add(album); context.SaveChanges(); }
public void ChangePriceOfTheAlbum(string albumId) { var searchedAlbum = this.db.Albums.Where(a => a.Id == albumId).FirstOrDefault(); decimal currentPrice = searchedAlbum.Tracks.Sum(p => p.Price); decimal priceWithPromotion = currentPrice - (decimal)0.13 * currentPrice; searchedAlbum.Price = priceWithPromotion; db.Albums.Update(searchedAlbum); db.SaveChanges(); }
public void CreateUser(string username, string passowrdHashed, string email) { var user = new User { Username = username, Password = passowrdHashed, Email = email }; using (var db = new IRunesDbContext()) { db.Users.Add(user); db.SaveChanges(); } }
public void CreateAlbum(string albumName, string albumCover) { var album = new Album { Name = albumName, Cover = albumCover }; using (var db = new IRunesDbContext()) { db.Albums.Add(album); db.SaveChanges(); } }
public void CreateTrack(string name, string albumId, string link, decimal price) { var track = new Track { AlbumId = Guid.Parse(albumId), Name = name, Link = link, Price = price }; using (var db = new IRunesDbContext()) { db.Tracks.Add(track); db.SaveChanges(); } }
public void AddAlbum(string artist, string title, MusicGenre genre, string coverArt) { Album album = new Album() { Artist = artist, Title = title, Genre = genre, CoverArt = coverArt }; Context.Albums.Add(album); Context.SaveChanges(); }
public void CreateAlbum(string name, string cover) { Album currentAlbum = new Album { Name = name, Cover = cover }; using (IRunesDbContext db = new IRunesDbContext()) { db.Albums.Add(currentAlbum); db.SaveChanges(); } }
public void AddAlbum(string name, string cover) { using (var context = new IRunesDbContext()) { var album = new Album() { Name = name, Cover = cover }; context.Albums.Add(album); context.SaveChanges(); } }
public void AddUser(string username, string firstName, string lastName, string email, string password) { User user = new User() { Username = username, FirstName = firstName, LastName = lastName, Email = email, Password = password }; Context.Users.Add(user); Context.SaveChanges(); }
public void AddTrack(string artist, string title, MusicGenre genre, string link, decimal price) { Track track = new Track() { Artist = artist, Title = title, Genre = genre, Link = link, Price = price }; Context.Tracks.Add(track); Context.SaveChanges(); }
public void AddUser(string username, string hashPassword, string email) { using (var context = new IRunesDbContext()) { var user = new User() { Username = username, Password = hashPassword, Email = email }; context.Users.Add(user); context.SaveChanges(); } }
public void CreateUser(string username, string passwordHashed, string email) { User currentUser = new User { Username = username, HashedPassword = passwordHashed, Email = email }; using (IRunesDbContext db = new IRunesDbContext()) { db.Users.Add(currentUser); db.SaveChanges(); } }
public void SaveUser(string username, string password, string email) { string hashedPassword = this.hashService.Hash(password); var user = new User { Id = Guid.NewGuid().ToString(), Username = username, Password = hashedPassword, Email = email }; context.Users.Add(user); context.SaveChanges(); }
public void AddAlbumTrack(Guid albumId, Guid trackId) { var album = Context.Albums.Find(albumId); var albumTrack = new AlbumTrack() { AlbumId = albumId, TrackId = trackId }; album.AlbumTracks.Add(albumTrack); var track = Context.Tracks.Find(trackId); album.Price += track.Price; Context.SaveChanges(); }
public void AddTrack(string name, string link, decimal price, int albumId) { using (var context = new IRunesDbContext()) { var track = new Track() { Name = name, Link = link, Price = price, AlbumId = albumId }; context.Tracks.Add(track); context.SaveChanges(); } }