public static BandItem ParseBandString(string str) { BandItem bi = new BandItem(); bi.Name = ""; bi.Freq1 = double.NaN; bi.Units1 = ""; bi.Freq2 = double.NaN; bi.Units2 = ""; if (str.Split(':').Count() < 4) { return(bi); } if (str.Split(':').Count() == 5) { bi.Name = str.Split(':')[4]; } bi.Freq1 = double.Parse(str.Split(':')[0].Replace('.', ',')); bi.Units1 = str.Split(':')[1]; bi.Freq2 = double.Parse(str.Split(':')[2].Replace('.', ',')); bi.Units2 = str.Split(':')[3]; return(bi); }
static void Main(string[] args) { Console.WriteLine(); Console.WriteLine($"Welcome to my record label's interactive client catalogue. Please select one of the following options:"); var userHasChosenToQuit = false; while (userHasChosenToQuit == false) { Console.WriteLine(); Console.WriteLine("Choose:"); Console.WriteLine("(A)dd a new band"); Console.WriteLine("(V)iew all the bands"); Console.WriteLine("A(d)d an album for a band"); Console.WriteLine("(L)et a band go"); Console.WriteLine("(R)esign a band"); Console.WriteLine("(E)nter a band's name to view all its albums"); Console.WriteLine("V(i)ew all albums ordered by release date"); Console.WriteLine("Vie(w) all bands that are signed"); Console.WriteLine("View all (b)ands that are not signed"); Console.WriteLine(); var choice = PromptForString("Choice: "); Console.WriteLine(); if (choice == "Q") { userHasChosenToQuit = true; } if (choice == "A") { var context = new BandDatabaseContext(); var newName = PromptForString("Name: "); var newCountryofOrigin = PromptForString("Country of Origin: "); var newNumberOfMembers = PromptForInteger("Number of Members: "); var newWeb = PromptForString("Email Address: "); var newStyle = PromptForString("Musical Style: "); var newIsSigned = PromptForBool("Is the band signed? (Answer as true or false): "); var newContactName = PromptForString("Name of Band Contact: "); var newContactPhone = PromptForString("Band Contact Phone Number: "); var newBandItem = new BandItem { Name = newName, CountryOfOrigin = newCountryofOrigin, NumberOfMembers = newNumberOfMembers, Web = newWeb, Style = newStyle, IsSigned = newIsSigned, ContactName = newContactName, ContactPhone = newContactPhone, }; context.Band.Add(newBandItem); context.SaveChanges(); } if (choice == "V") { var context = new BandDatabaseContext(); var allTheBands = context.Band; foreach (var band in allTheBands) { Console.WriteLine($"Band ID Number: {band.Id}, Name: {band.Name}, Country of Origin: {band.CountryOfOrigin}, Number of Members: {band.NumberOfMembers}, Email: {band.Web}, Signed?: {band.IsSigned}, Contact Name: {band.ContactName}, Contact Phone Number: {band.ContactPhone}"); } } if (choice == "d") { var context = new AlbumDatabaseContext(); var newTitle = PromptForString("Title: "); var newIsExplicit = PromptForBool("Is the album explicit? (Answer as true or false): "); var newReleaseDate = PromptForDateTime("What is the Album's release date in the format of MM/DD/YYYY?: "); var newBandId = PromptForInteger("What is the ID number for the band that recorded this album: "); var newAlbumItem = new AlbumItem { Title = newTitle, IsExplicit = newIsExplicit, ReleaseDate = newReleaseDate, BandId = newBandId }; context.Album.Add(newAlbumItem); context.SaveChanges(); } if (choice == "L") { var context = new BandDatabaseContext(); var bandWithNewSignedStatus = PromptForString("Which band would you like to select? "); var retrieveBandItem = context.Band.FirstOrDefault(entry => entry.Name == $"{bandWithNewSignedStatus}"); if (retrieveBandItem == null) { Console.WriteLine("Sorry, that band does not exist in this database."); } else { retrieveBandItem.IsSigned = false; context.SaveChanges(); } } if (choice == "R") { var context = new BandDatabaseContext(); var bandWithNewSignedStatus = PromptForString("Which band would you like to select? "); var retrieveBandItem = context.Band.FirstOrDefault(entry => entry.Name == $"{bandWithNewSignedStatus}"); if (retrieveBandItem == null) { Console.WriteLine("Sorry, that band does not exist in this database."); } else { retrieveBandItem.IsSigned = true; context.SaveChanges(); } } if (choice == "E") { var bandContext = new BandDatabaseContext(); var albumContext = new AlbumDatabaseContext(); var bandToSearchFor = PromptForString("Enter the name of the band you'd like to search for? "); var retrieveBandItem = bandContext.Band.FirstOrDefault(entry => entry.Name == $"{bandToSearchFor}"); if (retrieveBandItem == null) { Console.WriteLine("Sorry, that band does not exist in this database."); } else { var findAlbums = albumContext.Album.Where(entry => entry.BandId == retrieveBandItem.Id); foreach (var album in findAlbums) { Console.WriteLine(); Console.WriteLine($"Title: {album.Title}, Is Explicit?: {album.IsExplicit}, Release Date: {album.ReleaseDate}"); } } } if (choice == "i") { var context = new AlbumDatabaseContext(); var allTheAlbums = context.Album.OrderBy(entry => entry.ReleaseDate); foreach (var album in allTheAlbums) { Console.WriteLine($"Album Title: {album.Title}, Release Date: {album.ReleaseDate}"); } } if (choice == "w") { var context = new BandDatabaseContext(); var allTheBands = context.Band.Where(band => band.IsSigned == true); foreach (var band in allTheBands) { Console.WriteLine(band.Name); } } if (choice == "b") { var context = new BandDatabaseContext(); var allTheBands = context.Band.Where(band => band.IsSigned == false); foreach (var band in allTheBands) { Console.WriteLine(band.Name); } } } }