public async Task AddToCart(Album album, CancellationToken cancellationToken = default) { await PopupaleShoppingCartId(cancellationToken).ConfigureAwait(false); // Get the matching cart and album instances var cartItem = await _dbContext.Carts.SingleOrDefaultAsync( c => c.CartId == ShoppingCartId && c.AlbumId == album.AlbumId, cancellationToken).ConfigureAwait(false); if (cartItem == null) { // Create a new cart item if no cart item exists cartItem = new Cart() { AlbumId = album.AlbumId, CartId = ShoppingCartId, Count = 1, DateCreated = DateTime.Now }; await _dbContext.Carts.AddAsync(cartItem).ConfigureAwait(false); } else { // If the item does exist in the cart, then add one to the quantity cartItem.Count++; } await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); }
public async Task <Album> Create(Album album, CancellationToken cancellationToken = default) { await _dbContext.AddAsync(album, cancellationToken).ConfigureAwait(false); await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); return(album); }
public async Task <IActionResult> Create([Bind("ArtistId,BandId,ArtistName")] Artist artist) { if (ModelState.IsValid) { _context.Add(artist); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(artist)); }
public async Task <IActionResult> Create([Bind("SongId,ArtistId,BandId,CategoryId,ArtistName,timeDuration,Popularity,Price")] Song song) { if (ModelState.IsValid) { _context.Add(song); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(song)); }
public async Task <IActionResult> Create([Bind("BandId,CategoryId,BandName")] Bands bands) { if (ModelState.IsValid) { _context.Add(bands); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(bands)); }
private async Task PopulateDbAsync(MusicStoreDbContext db) { var firstSong = new Song { Id = 1, Name = SongName, Price = SongPrice, Duration = SongDuration, ArtistId = SongArtistId }; var secondSong = new Song { Id = 2, Name = "SecondSong", Price = 2.5m, ArtistId = 2 }; var thirdSong = new Song { Id = 3, Name = "ThirdSong", Price = 9.5m, ArtistId = 3 }; var firstArtist = new Artist { Id = 1, Name = ArtistName }; var secondArtist = new Artist { Id = 2, Name = ArtistName }; var thirdArtist = new Artist { Id = 3, Name = ArtistName }; firstArtist.Songs.Add(firstSong); await db.Songs.AddRangeAsync(firstSong, secondSong, thirdSong); await db.Artists.AddRangeAsync(firstArtist, secondArtist, thirdArtist); await db.SaveChangesAsync(); }
public async Task <Order> AddOrder(Order item, CancellationToken cancellationToken = default) { _dbContext.Orders.Add(item); await _dbContext.SaveChangesAsync(cancellationToken); return(item); }
public async Task AddAlbumAsync(int groupId, int albumId) { DbAlbumGroupAlbumPosition entity = await _context.AlbumGroupListPositions.SingleOrDefaultAsync(x => x.GroupId == groupId && x.AlbumId == albumId); if (entity == null) { var group = await _context.AlbumGroups.SingleOrDefaultAsync(x => x.Id == groupId); if (group == null) { throw new EntityNotFoundRepositoryException($"Album group with ID {groupId} not found"); } var album = await _context.Albums.SingleOrDefaultAsync(x => x.Id == albumId); if (album == null) { throw new EntityNotFoundRepositoryException($"Album with ID {albumId} not found"); } var totalItemsInGroup = _context.AlbumGroups.SelectMany(x => x.Items).Count(); entity = new DbAlbumGroupAlbumPosition { Album = album, CreatedUtc = DateTime.UtcNow, Group = group, PositionIndex = totalItemsInGroup + 1 }; await _context.AlbumGroupListPositions.AddAsync(entity); await _context.SaveChangesAsync(); } }
public async Task <GenreDetail> AddAsync(string genre) { var dbGenre = await _context.Genres.SingleOrDefaultAsync(x => x.Name == genre); if (dbGenre == null) { dbGenre = new DbGenre() { Name = genre, CreatedUtc = DateTime.UtcNow }; _context.Genres.Add(dbGenre); await _context.SaveChangesAsync(); return(new GenreDetail() { Name = dbGenre.Name, TotalAlbums = 0, TotalArtists = 0, Created = new DateTime(dbGenre.CreatedUtc.Ticks, DateTimeKind.Utc) }); } else { var numAlbums = await _context.Genres.Where(g => g.Name == genre).SelectMany(x => x.AlbumGenres).CountAsync(x => x.Album.PublishStatus == DbPublishedStatus.PUBLISHED); var numArtists = await _context.Genres.Where(g => g.Name == genre).SelectMany(x => x.ArtistGenres).CountAsync(x => x.Artist.PublishStatus == DbPublishedStatus.PUBLISHED); return(new GenreDetail() { Name = dbGenre.Name, TotalAlbums = numAlbums, TotalArtists = numArtists, Created = new DateTime(dbGenre.CreatedUtc.Ticks, DateTimeKind.Utc) }); } }
public async Task <IActionResult> RunMigrationPosted([FromQuery] string migrationName, [FromServices] MusicStoreDbContext context, [FromServices] IHostingEnvironment env, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); if (!_migrations.Contains(migrationName)) { return(NoContent()); } migrationName = _migrations.Single(x => x.Eq(migrationName)); var file = env.ContentRootFileProvider.GetFileInfo(Path.Combine("wwwroot", "data", $"{migrationName}.json")); JArray array = null; if (file.Exists) { using (var stream = file.CreateReadStream()) using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) using (var jReader = new JsonTextReader(reader)) { array = await JArray.LoadAsync(jReader, cancellationToken); } } if (string.Compare("genres", migrationName, true) == 0) { List <Genre> genres = new List <Genre>(); foreach (JObject item in array) { string name = item.GetValue("name").Value <string>(); genres.Add(new Genre() { Name = name }); } await context.Genres.AddRangeAsync(genres); await context.SaveChangesAsync(); } else if (string.Compare("artists", migrationName, true) == 0) { List <Artist> artists = new List <Artist>(); foreach (JObject item in array) { string name = item.GetValue("name").Value <string>(); artists.Add(new Artist() { Name = name }); } await context.Artists.AddRangeAsync(artists); await context.SaveChangesAsync(); } else if (string.Compare("albums", migrationName, true) == 0) { Dictionary <string, Genre> genres = new Dictionary <string, Genre>(); Dictionary <string, Artist> artists = new Dictionary <string, Artist>(); List <Album> albums = new List <Album>(); foreach (JObject item in array) { string name = item.GetValue("name").Value <string>(); decimal price = item.GetValue("price").Value <decimal>(); string albumUrl = item.GetValue("albumArtUrl").Value <string>(); string artist = item.GetValue("artist").Value <string>(); string genre = item.GetValue("genre").Value <string>(); if (!genres.ContainsKey(genre)) { var genDb = await context.Genres.FirstOrDefaultAsync(x => x.Name == genre); genres.Add(genre, genDb); } if (!artists.ContainsKey(artist)) { var artDb = await context.Artists.FirstOrDefaultAsync(x => x.Name == artist); artists.Add(artist, artDb); } albums.Add(new Album { Title = name, Price = price, AlbumArtUrl = albumUrl, Genre = genres[genre], Artist = artists[artist] }); } await context.Albums.AddRangeAsync(albums); await context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); }
public async Task <bool> SaveAsync() { return(await _context.SaveChangesAsync() > 0); }
public async Task <AlbumDetail> UpdateAsync(int albumId, Album album) { PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper(); var dbalbum = await _context.Albums .Include(x => x.Artist) .Include(x => x.AlbumGenres) .ThenInclude(x => x.Genre) .Include(x => x.Tracks) .SingleOrDefaultAsync(x => x.Id == albumId); if (dbalbum != null) { dbalbum.Title = album.Title; dbalbum.DescriptionText = album.DescriptionText; dbalbum.PublishStatus = statusMapper.Map(album.PublishedStatus); dbalbum.Label = album.Label; dbalbum.Price = album.Price; dbalbum.Producer = album.Producer; dbalbum.ReleaseDate = album.ReleaseDate; dbalbum.TotalDurationInSeconds = album.TotalDurationInSeconds; dbalbum.ArtistId = album.ArtistId; // remove any existing genres that are not present on input model _context.AlbumGenres.RemoveRange(dbalbum.AlbumGenres.Where(x => x.AlbumId == albumId && !album.Genres.Contains(x.Genre.Name))); // add any genreas not already in the DB relationship foreach (string newGenreName in album.Genres) { if (dbalbum.AlbumGenres.FirstOrDefault(x => x.Genre.Name == newGenreName) == null) { var newGenreEntity = await _context.Genres.SingleOrDefaultAsync(x => x.Name == newGenreName); if (newGenreEntity != null) { dbalbum.AlbumGenres.Add(new DbAlbumGenre() { Genre = newGenreEntity, CreatedUtc = DateTime.UtcNow }); } else { // invalid genre throw new RepositoryException($"The supplied genre '{newGenreName}' does not exist."); } } } if (album.CoverImageId.HasValue) { var img = await this._context.ImageResources.SingleOrDefaultAsync(x => x.Id == album.CoverImageId.Value); if (img != null) { dbalbum.AlbumCoverImage = img; } else { throw new RepositoryException($"Invalid {nameof(album.CoverImageId)}, no image for ID"); } } // find any tracks with database ID's and remove anything in the database with an ID not in this list List <int> existingTrackIds = album.Tracks.Where(t => t.TrackId.HasValue).Select(t => t.TrackId.Value).ToList(); _context.Tracks.RemoveRange(dbalbum.Tracks.Where(x => x.AlbumId == albumId && !existingTrackIds.Contains(x.Id))); // now that any existing tracks which are not in the supplied model add or update based on the presence of a trackId foreach (var t in album.Tracks) { DbTrack existingTrack = null; if (t.TrackId.HasValue) { existingTrack = await _context.Tracks.SingleOrDefaultAsync(x => x.Id == t.TrackId.Value && x.AlbumId == albumId); } if (existingTrack != null) { // update track existingTrack.TrackNumber = t.TrackNumber; existingTrack.Title = t.Title; existingTrack.DurationInSeconds = t.DurationInSeconds; existingTrack.UpdatedUtc = DateTime.UtcNow; } else { //create new track dbalbum.Tracks.Add( new DbTrack { CreatedUtc = DateTime.UtcNow, DurationInSeconds = t.DurationInSeconds, Title = t.Title, TrackNumber = t.TrackNumber, UpdatedUtc = DateTime.UtcNow } ); } } await _context.SaveChangesAsync(); return(this._mapper.MapToDetailRep(dbalbum)); } else { throw new EntityNotFoundRepositoryException($"Album with ID {albumId} not found"); } }
public async Task <ArtistDetail> UpdateAsync(int artistId, Artist artist) { PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper(); var dbartist = await _context.Artists .Include(x => x.ArtistGenres) .ThenInclude(x => x.Genre) .SingleOrDefaultAsync(x => x.Id == artistId); if (dbartist != null) { dbartist.Name = artist.Name; dbartist.UpdatedUtc = DateTime.UtcNow; dbartist.BioText = artist.BioText; dbartist.PublishStatus = statusMapper.Map(artist.PublishedStatus); // remove any existing genres that are not present on input model _context.ArtistGenres.RemoveRange(dbartist.ArtistGenres.Where(x => x.ArtistId == artistId && !artist.Genres.Contains(x.Genre.Name))); // add any genreas not already in the DB relationship foreach (string newGenreName in artist.Genres) { if (dbartist.ArtistGenres.FirstOrDefault(x => x.Genre.Name == newGenreName) == null) { var newGenreEntity = await _context.Genres.SingleOrDefaultAsync(x => x.Name == newGenreName); if (newGenreEntity != null) { dbartist.ArtistGenres.Add(new DbArtistGenre() { Genre = newGenreEntity, CreatedUtc = DateTime.UtcNow }); } else { // invalid genre throw new RepositoryException($"The supplied genre '{newGenreName}' does not exist."); } } } if (artist.BioImageId.HasValue) { var img = await this._context.ImageResources.SingleOrDefaultAsync(x => x.Id == artist.BioImageId.Value); if (img != null) { dbartist.BioImage = img; } else { throw new RepositoryException($"Invalid {nameof(artist.BioImageId)}, no image for ID"); } } await _context.SaveChangesAsync(); return(this._mapper.MapToDetailRep(dbartist)); } else { throw new EntityNotFoundRepositoryException($"Artist with ID {artistId} not found"); } }
public async Task <bool> SaveChangesAsync() { var res = await dbContext.SaveChangesAsync(); return(res > 0); }
public async Task CreateSeedContent() { DbArtist tempArtistResult = null; tempArtistResult = await CreateArtist("Beck", "Bio text...", new string[] { "Indie", "Electronic" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Modern Guilt", description : "", genres : new string[] { "Alternative" }, producer : "Danger Mouse, Beck", label : "DGC Records", releaseDate : new DateTime(2008, 7, 8), price : 13.99, coverImagePath : "Images/Covers/Beck_ModernGuilt.jpg", tracks : new TrackStruct[] { new TrackStruct("Orphans", "3:15"), new TrackStruct("Gamma Ray", "2:57"), new TrackStruct("Chemtrails", "4:40"), new TrackStruct("Modern Guilt", "3:14"), new TrackStruct("Youthless", "3:00"), new TrackStruct("Walls", "2:22"), new TrackStruct("Replica", "3:25"), new TrackStruct("Soul of a Man", "2:36"), new TrackStruct("Profanity Prayers", "3:43"), new TrackStruct("Volcano", "4:26") }); await CreateAlbum( artistId : tempArtistResult.Id, title : "Guero", description : "", genres : new string[] { "Electronic", "Hip Hop", "Rock" }, producer : "Beck Hansen, Dust Brothers, Tony Hoffer", label : "Interscope Records", releaseDate : new DateTime(2005, 3, 21), price : 13.99, coverImagePath : "Images/Covers/beckguero.jpg", tracks : new TrackStruct[] { new TrackStruct("E-Pro", "3:22"), new TrackStruct("Qué Onda Guero", "3:29"), new TrackStruct("Girl", "3:30"), new TrackStruct("Missing", "4:44"), new TrackStruct("lack Tambourine", "2:46"), new TrackStruct("Earthquake Weather", "4:26"), new TrackStruct("Hell Yes", "3:18"), new TrackStruct("Broken Drum", "4:30"), new TrackStruct("Scarecrow", "4:16"), new TrackStruct("Go It Alone", "4:09"), new TrackStruct("Farewell Ride", "4:19"), new TrackStruct("Rental Car", "3:05"), new TrackStruct("Emergency Exit", "4:01"), new TrackStruct("Send A Message To Her", "4:28"), new TrackStruct("Chain Reaction", "3:27"), new TrackStruct("Clap Hands", "3:19") }); tempArtistResult = await CreateArtist("Fleetwood Mac", "Bio text...", new string[] { "Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Rumours", description : "", genres : new string[] { "Rock" }, producer : "Fleetwood Mac, Ken Caillat, Richard Dashut", label : "Warner Bros", releaseDate : new DateTime(1977, 2, 4), price : 13.99, coverImagePath : "Images/Covers/FMacRumours.png", tracks : new TrackStruct[] { new TrackStruct("Second Hand News", "2:56"), new TrackStruct("Dreams", "4:14"), new TrackStruct("Never Going Back Again", "2:14"), new TrackStruct("Dont Stop", "3:13"), new TrackStruct("Go Your Own Way", "3:13"), new TrackStruct("Songbird", "3:30"), new TrackStruct("The Chain", "4:30"), new TrackStruct("You Make Loving Fun", "3:31"), new TrackStruct("I Don't Want to Know", "3:15"), new TrackStruct("Oh Daddy", "3:56"), new TrackStruct("Gold Dust Woman", "4:56") }); tempArtistResult = await CreateArtist("LCD Soundsystem", "", new string[] { "Dance-Punk", "Electronica", "Electronic Rock", "Alt-Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Sound of Silver", description : "", genres : new string[] { "Dance-Punk", "Electronica", "Electronic Rock" }, producer : "DFA, Capitol, EMI", label : "The DFA", releaseDate : new DateTime(2007, 3, 12), price : 13.99, coverImagePath : "Images/Covers/SoundOfSilver.jpg", tracks : new TrackStruct[] { new TrackStruct("Get Innocuous!", "7:11"), new TrackStruct("Time to Get Away", "4:11"), new TrackStruct("North American scum", "5:25"), new TrackStruct("Someone Great", "6:25"), new TrackStruct("All My Friends", "7:37"), new TrackStruct("Us v Them", "8:29"), new TrackStruct("Watch the Tapes", "3:55"), new TrackStruct("Sound of Silver", "7:07"), new TrackStruct("New York, I Love You but You're Bringing Me Down", "5:35") }); tempArtistResult = await CreateArtist("Arcade Fire", "", new string[] { "Rock", "Indie-Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Funeral", description : "", genres : new string[] { "Indie-Rock", "Rock" }, producer : "Arcade Fire", label : "Merge", releaseDate : new DateTime(2004, 9, 14), price : 13.99, coverImagePath : "Images/Covers/afFuneral.jpg", tracks : new TrackStruct[] { new TrackStruct("Neighborhood #1 (Tunnels)", "4:48"), new TrackStruct("Neighborhood #2 (Laïka)", "3:32"), new TrackStruct("Une Année Sans Lumière", "3:41"), new TrackStruct("Neighborhood #3 (Power Out)", "5:12"), new TrackStruct("Neighborhood #4 (7 Kettles)", "4:49"), new TrackStruct("Crown Of Love", "4:42"), new TrackStruct("Wake Up", "5:35"), new TrackStruct("Haïti", "4:07"), new TrackStruct("Rebellion(Lies)", "5:12"), new TrackStruct("In The Backseat", "6:20") }); tempArtistResult = await CreateArtist("Pixies", "", new string[] { "Noise-Pop", "Alt-Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Doolittle", description : "", genres : new string[] { "Noise-Pop", "Alt-Rock" }, producer : "Gil Norton", label : "4AD, Elektra", releaseDate : new DateTime(1998, 10, 23), price : 13.99, coverImagePath : "Images/Covers/Pixies-Doolittle.jpg", tracks : new TrackStruct[] { new TrackStruct("Debaser", "2:52"), new TrackStruct("Tame", "1:55"), new TrackStruct("Wave Of Mutilation", "2:04"), new TrackStruct("I Bleed", "2:34"), new TrackStruct("Here Comes Your Man", "3:21"), new TrackStruct("Dead", "2:21"), new TrackStruct("Monkey Gone To Heaven", "2:57"), new TrackStruct("Mr.Grieves", "2:05"), new TrackStruct("Crackity Jones", "1:24"), new TrackStruct("La La Love You", "2:43"), new TrackStruct("No. 13 Baby", "3:51"), new TrackStruct("There Goes My Gun", "1:49"), new TrackStruct("Hey", "3:31"), new TrackStruct("Silver", "2:25"), new TrackStruct("Gouge Away", "2:45") }); tempArtistResult = await CreateArtist("Wilco", "", new string[] { "Alt-rock", "Indie-Rock", "Alternative country" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Yankee Hotel Foxtrot", description : "", genres : new string[] { "Alt-rock", "Indie-Rock" }, producer : "Wilco", label : "Nonesuch", releaseDate : new DateTime(1998, 10, 23), price : 13.99, coverImagePath : "Images/Covers/yankeehotelfoxtrot.jpg", tracks : new TrackStruct[] { new TrackStruct("I Am Trying To Break Your Heart", "6:57"), new TrackStruct("Kamera", "3:29"), new TrackStruct("Radio Cure ", "5:08"), new TrackStruct("War On War", "3:47"), new TrackStruct("Jesus, Etc.", "3:50"), new TrackStruct("Ashes Of American Flags", "4:43"), new TrackStruct("Heavy Metal Drummer", "3:08"), new TrackStruct("I'm The Man Who Loves You", "3:55"), new TrackStruct("Pot Kettle Black", "4:00"), new TrackStruct("Poor Places", "5:15"), new TrackStruct("Reservations", "7:22") }); await CreateAlbum( artistId : tempArtistResult.Id, title : "Sky Blue Sky", description : "", genres : new string[] { "Alt-rock", "Indie-Rock" }, producer : "Wilco", label : "Nonesuch", releaseDate : new DateTime(2007, 5, 15), price : 13.99, coverImagePath : "Images/Covers/skybluesky.jpg", tracks : new TrackStruct[] { new TrackStruct("Either Way", "3:01"), new TrackStruct("You Are My Face", "4:39"), new TrackStruct("Impossible Germany", "5:58"), new TrackStruct("Sky Blue Sky", "3:24"), new TrackStruct("Side With The Seeds", "4:16"), new TrackStruct("Shake It Off", "5:43"), new TrackStruct("Please Be Patient With Me", "3:20"), new TrackStruct("Hate It Here", "4:34"), new TrackStruct("Leave Me(Like You Found Me)", "4:11"), new TrackStruct("Walken", "4:28"), new TrackStruct("What Light ", "3:36"), new TrackStruct("On And On And On", "4:02"), }); tempArtistResult = await CreateArtist("Pearl Jam", "Bio text...", new string[] { "Grunge", "Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Ten", description : "", genres : new string[] { "Alt-rock", "Grunge" }, producer : "Rick Parashar, Pearl Jam", label : "Epic", releaseDate : new DateTime(1991, 8, 27), price : 9.99, coverImagePath : "Images/Covers/pjTen.jpg", tracks : new TrackStruct[] { new TrackStruct("Once", "3:51"), new TrackStruct("Even Flow", "4:53"), new TrackStruct("Alive", "5:40"), new TrackStruct("Why Go", "3:19"), new TrackStruct("Black", "5:43"), new TrackStruct("Jeremy", "5:18"), new TrackStruct("Oceans", "2:41"), new TrackStruct("Porch", "3:30"), new TrackStruct("Garden", "4:58"), new TrackStruct("Deep", "4:13"), new TrackStruct("Release", "5:05"), new TrackStruct("Master / Slave", "3:43"), }); tempArtistResult = await CreateArtist("Graham Coxon", "Bio text...", new string[] { "Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Love Travels At Illegal Speeds", description : "", genres : new string[] { "Rock", "Alternative Rock", "Brit Pop" }, producer : "Stephen Street", label : "Parlophone", releaseDate : new DateTime(2006, 3, 8), price : 9.99, coverImagePath : "Images/Covers/gc-ltais.jpeg", tracks : new TrackStruct[] { new TrackStruct("Standing On My Own Again", "4:29"), new TrackStruct("I Can't Look At Your Skin", "3:35"), new TrackStruct("Don't Let Your Man Know", "2:54"), new TrackStruct("Just A State Of Mind", "4:36"), new TrackStruct("You & I", "3:42"), new TrackStruct("Gimme Some Love", "2:32"), new TrackStruct("I Don't Wanna Go Out", "4:17"), new TrackStruct("Don't Believe Anything I Say", "5:26"), new TrackStruct("Tell It Like It Is", "4:02"), new TrackStruct("Flights To The Sea (Lovely Rain)", "3:25"), new TrackStruct("What's He Got?", "3:42"), new TrackStruct("You Always Let Me Down", "2:49"), new TrackStruct("See A Better Day", "5:10"), new TrackStruct("Click Click Click", "2:54"), new TrackStruct("Livin'", "3:42"), }); tempArtistResult = await CreateArtist("Yeah Yeah Yeahs", "Bio text...", new string[] { "Rock", "Electronic", "Alternative Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "It's Blitz!", description : "", genres : new string[] { "Rock", "Alternative Rock", "Electronic" }, producer : "Nick Launay, David Sitek", label : "Dress Up, DGC, Interscope", releaseDate : new DateTime(2009, 3, 6), price : 9.99, coverImagePath : "Images/Covers/itsblitz.jpeg", tracks : new TrackStruct[] { new TrackStruct("Zero", "4:26"), new TrackStruct("Heads Will Roll", "3:42"), new TrackStruct("Soft Shock", "3:53"), new TrackStruct("Skeletons", "5:02"), new TrackStruct("Dull Life", "4:08"), new TrackStruct("Shame And Fortune", "3:31"), new TrackStruct("Runaway", "5:13"), new TrackStruct("Dragon Queen", "4:02"), new TrackStruct("Hysteric", "3:52"), new TrackStruct("Little Shadow", "3:57"), }); tempArtistResult = await CreateArtist("The Flaming Lips", "Bio text...", new string[] { "Experimental", "Indie Rock", "Psychedelic Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "The Soft Bulletin", description : "", genres : new string[] { "Experimental", "Indie Rock", "Psychedelic Rock" }, producer : "Dave Fridmann", label : "Warner Bros", releaseDate : new DateTime(1999, 5, 17), price : 9.99, coverImagePath : "Images/Covers/flaminglipstsb.jpeg", tracks : new TrackStruct[] { new TrackStruct("Race For The Prize", "4:18"), new TrackStruct("A Spoonful Weighs A Ton", "3:32"), new TrackStruct("The Spark That Bled", "5:55"), new TrackStruct("Slow Motion", "3:53"), new TrackStruct("What Is The Light?", "4:05"), new TrackStruct("The Observer", "4:10"), new TrackStruct("Waitin' For A Superman", "4:17"), new TrackStruct("Suddenly Everything Has Changed", "3:54"), new TrackStruct("The Gash", "4:02"), new TrackStruct("Feeling Yourself Disintegrate", "5:17"), new TrackStruct("Sleeping On The Roof", "3:10"), new TrackStruct("Race For The Prize", "4:09"), new TrackStruct("Waitin' For A Superman", "4:19"), new TrackStruct("Buggin'", "3:16") }); tempArtistResult = await CreateArtist("Pavement", "Bio text...", new string[] { "Indie Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Crooked Rain, Crooked Rain", description : "", genres : new string[] { "Indie Rock" }, producer : "Pavement", label : "Big Cat", releaseDate : new DateTime(1999, 5, 17), price : 9.99, coverImagePath : "Images/Covers/crookedrain.jpeg", tracks : new TrackStruct[] { new TrackStruct("Silence Kit", "3:00"), new TrackStruct("Elevate Me Later", "2:51"), new TrackStruct("Stop Breathin", "4:27"), new TrackStruct("Cut Your Hair", "3:06"), new TrackStruct("Newark Wilder", "3:53"), new TrackStruct("Unfair", "2:33"), new TrackStruct("Gold Soundz", "2:39"), new TrackStruct("5-4 = Unity", "2:09"), new TrackStruct("Range Life", "4:54"), new TrackStruct("Heaven Is A Truck", "2:30"), new TrackStruct("Hit The Plane Down", "3:36"), new TrackStruct("Fillmore Jive", "6:38") }); tempArtistResult = await CreateArtist("Doves", "Bio text...", new string[] { "Indie Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Lost Souls", description : "", genres : new string[] { "Brit Pop", "Indie Rock" }, producer : "Doves; Steve Osborne", label : "Heavenly Records", releaseDate : new DateTime(2000, 5, 3), price : 9.99, coverImagePath : "Images/Covers/lostsouls.jpeg", tracks : new TrackStruct[] { new TrackStruct("Firesuite", "4:36"), new TrackStruct("Here It Comes", "4:50"), new TrackStruct("Break Me Gently", "4:38"), new TrackStruct("Sea Song", "6:12"), new TrackStruct("Rise", "5:38"), new TrackStruct("Lost Souls", "6:09"), new TrackStruct("Melody Calls", "3:27"), new TrackStruct("Catch The Sun", "4:49"), new TrackStruct("The Man Who Told Everything", "5:47"), new TrackStruct("The Cedar Room", "7:38"), new TrackStruct("Reprise", "1:45"), new TrackStruct("A House", "3:40") }); tempArtistResult = await CreateArtist("Queens of the Stone Age", "Bio text...", new string[] { "Rock", "Indie Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Rated R", description : "", genres : new string[] { "Rock" }, producer : "Chris Goss, Joshua Homme", label : "Heavenly Records", releaseDate : new DateTime(2000, 6, 5), price : 9.99, coverImagePath : "Images/Covers/qotsar.jpeg", tracks : new TrackStruct[] { new TrackStruct("Feel Good Hit Of The Summer", "2:43"), new TrackStruct("The Lost Art Of Keeping A Secret", "3:36"), new TrackStruct("Leg Of Lamb", "2:48"), new TrackStruct("Auto Pilot", "4:01"), new TrackStruct("Better Living Through Chemistry", "5:49"), new TrackStruct("Monsters In The Parasol", "3:27"), new TrackStruct("Quick And To The Pointless", "1:42"), new TrackStruct("In The Fade", "3:51"), new TrackStruct("Untitled", "0:34"), new TrackStruct("Tension Head", "2:52"), new TrackStruct("Lightning Song", "2:07"), new TrackStruct("I Think I Lost My Headache", "8:40") }); tempArtistResult = await CreateArtist("The Go! Team", "Bio text...", new string[] { "Leftfield", "Abstract", "Electro", "Future Jazz" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Thunder, Lightning, Strike", description : "", genres : new string[] { "Leftfield", "Abstract", "Electro", "Future Jazz" }, producer : "The Go! Team, Gareth Parton", label : "Memphis Industries", releaseDate : new DateTime(2004, 9, 13), price : 9.99, coverImagePath : "Images/Covers/thunderlightningstrike.jpeg", tracks : new TrackStruct[] { new TrackStruct("Panther Dash", "2:42"), new TrackStruct("Ladyflash", "4:07"), new TrackStruct("Feelgood By Numbers", "1:56"), new TrackStruct("The Power Is On", "3:11"), new TrackStruct("Get It Together", "3:24"), new TrackStruct("Junior Kickstart", "3:30"), new TrackStruct("Air Raid Gtr", "0:41"), new TrackStruct("Bottle Rocket", "3:40"), new TrackStruct("Friendship Update", "3:58"), new TrackStruct("Huddle Formation", "3:09"), new TrackStruct("Everyone's A V.I.P. To Someone", "4:55") }); List <int> groupIds = _context.AlbumGroups.Select(x => x.Id).ToList(); // randomize the item order in each group foreach (var groupId in groupIds) { var items = _context.AlbumGroupListPositions.Where(x => x.GroupId == groupId) .AsEnumerable() .OrderBy(x => Guid.NewGuid()); int i = 1; foreach (var itm in items) { itm.PositionIndex = i; i++; } await _context.SaveChangesAsync(); } }
public async Task Seed() { // create the database contexts and apply any pending migrations if (_context.Database.GetPendingMigrations().Any()) { _context.Database.Migrate(); } if (_identityServerConfigContext.Database.GetPendingMigrations().Any()) { _identityServerConfigContext.Database.Migrate(); } if (_identityServerPersistedGrantContext.Database.GetPendingMigrations().Any()) { _identityServerPersistedGrantContext.Database.Migrate(); } if ((await _roleManager.FindByNameAsync("AdminUserClassicRole")) == null) { var addedRole = new DbRole { Name = "AdminUserClassicRole", Description = "classic style admin role" }; var addRoleResult = await _roleManager.CreateAsync(addedRole); if (addRoleResult.Succeeded) { await _roleManager.AddClaimAsync(addedRole, new Claim(ClaimTypes.Role, "AdminUSerClassicRoleClaim")); } } string emailUsername = "******"; DbUser user = await _userManager.FindByNameAsync(emailUsername); if (user == null) { var result = await _userManager.CreateAsync(new DbUser { UserName = emailUsername, DateOfBirth = new DateTime(1970, 1, 1), Email = emailUsername, Firstname = "test", LockoutEnabled = true, Surname = "user", EmailConfirmed = true, TwoFactorEnabled = false }, "Pa$$word1"); if (result.Succeeded) { user = await _userManager.FindByNameAsync(emailUsername); await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, MusicStoreConstants.Roles.AdminUser)); await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, MusicStoreConstants.Roles.TestUser)); await _userManager.AddClaimAsync(user, new Claim(MusicStoreConstants.CLaimTypes.MusicStoreApiReadAccess, "true")); await _userManager.AddClaimAsync(user, new Claim(MusicStoreConstants.CLaimTypes.MusicStoreApiWriteAccess, "true")); var addRoleResult = await _userManager.AddToRoleAsync(user, "AdminUserClassicRole"); } else { _logger.LogError("Error adding user - error: " + string.Join(", ", result.Errors.Select(e => e.Description))); } } if (!_identityServerConfigContext.Clients.Any()) { IdentityServerConfigUrls urls = new IdentityServerConfigUrls() { AngularAppClientUri = "https://localhost:44350", MvcClientUri = "https://localhost:44357" }; string angularClientUrl = this._configuration.GetValue <string>("AngularAppClientUrl"); if (!string.IsNullOrWhiteSpace(angularClientUrl)) { urls.AngularAppClientUri = angularClientUrl; } // set url for the server side mvc app "/samples/oauthtest" string mvcAppClientUrl = this._configuration.GetValue <string>("MvcAppClientUrl"); if (!string.IsNullOrWhiteSpace(mvcAppClientUrl)) { urls.MvcClientUri = mvcAppClientUrl; } foreach (var client in IdentityServerClients.GetClients(urls)) { _identityServerConfigContext.Clients.Add(client.ToEntity()); } _identityServerConfigContext.SaveChanges(); } if (!_identityServerConfigContext.IdentityResources.Any()) { foreach (var resource in IdentityServerResources.GetIdentityResources()) { _identityServerConfigContext.IdentityResources.Add(resource.ToEntity()); } _identityServerConfigContext.SaveChanges(); } if (!_identityServerConfigContext.ApiResources.Any()) { foreach (var resource in IdentityServerResources.GetApiResources()) { _identityServerConfigContext.ApiResources.Add(resource.ToEntity()); } _identityServerConfigContext.SaveChanges(); } ContentCreator contentCreator = new ContentCreator(_context); if (await _context.AlbumGroups.CountAsync() == 0) { //create default groups await _context.AlbumGroups.AddAsync(new DbAlbumGroup { Key = "FEATURED_ALBUMS", Name = "Featured albums", CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow }); await _context.AlbumGroups.AddAsync(new DbAlbumGroup { Key = "NEW_ALBUMS", Name = "New albums", CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow }); await _context.AlbumGroups.AddAsync(new DbAlbumGroup { Key = "BESTSELLING_ALBUMS", Name = "Bestselling albums", CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow }); await _context.SaveChangesAsync(); } if (await _context.Genres.CountAsync() == 0) { await contentCreator.CreateGenres("Rock", "Pop", "Indie", "Funk", "Grunge", "Electronic", "Punk", "Alternative"); } if (await _context.Artists.CountAsync() == 0) { await contentCreator.CreateSeedContent(); } }
public void Remove(Album album) { _context.Albums.Remove(album); _context.SaveChangesAsync(); }