コード例 #1
0
        public void AddSong(int trackNumber, string songTitle, decimal duration, int albumId)
        {
            var context = new RhythmsGonnaGetYouContext();
            var song    = new Song
            {
                TrackNumber = trackNumber,
                Title       = songTitle,
                Duration    = duration,
                AlbumId     = albumId
            };

            context.Songs.Add(song);
            context.SaveChanges();
        }
コード例 #2
0
        public void AddAlbum(string albumTitle, int bandId, string isExplicit)
        {
            var context = new RhythmsGonnaGetYouContext();
            var album   = new Album
            {
                Title       = albumTitle,
                ReleaseDate = DateTime.Now,
                BandId      = bandId,
                IsExplicit  = isExplicit
            };

            context.Albums.Add(album);
            context.SaveChanges();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var context = new RhythmsGonnaGetYouContext();

            Greeting("Welcome to Rhythms Gonna Get You Records Database:");

            var userChoice = false;

            while (userChoice == false)
            {
                Console.WriteLine("\n");
                Console.WriteLine("Menu Options:");
                Console.WriteLine("\n");
                Console.WriteLine("View");
                Console.WriteLine("Current Clients");
                Console.WriteLine("Add");
                Console.WriteLine("Change Contract");
                Console.WriteLine("Quit");
                Console.WriteLine("\n");
                Console.WriteLine("Which choice would you like? \n");

                var menuChoice = Console.ReadLine().ToLower().Trim();

                switch (menuChoice)
                {
                case "view":
                    Console.WriteLine("\n\n");
                    Console.WriteLine("View Options:");
                    Console.WriteLine("\n");
                    Console.WriteLine("All Bands");
                    Console.WriteLine("All Albums");
                    Console.WriteLine("Band Albums");
                    Console.WriteLine("Albums In Genre");
                    Console.WriteLine("Members in Band");
                    Console.WriteLine("\n");

                    var viewChoice = Console.ReadLine().ToLower().Trim();
                    switch (viewChoice)
                    {
                    case "all bands":
                        foreach (var band in context.Bands)
                        {
                            Console.WriteLine($"{band.Name}");
                        }
                        break;

                    case "all albums":
                        foreach (var album in context.Albums.OrderBy(albums => albums.ReleaseDate))
                        {
                            Console.WriteLine($"{album.Title}");
                        }
                        break;

                    case "band albums":
                        var bandChoice = ReadInput("What band are you looking for?\n");

                        Console.WriteLine($"\nThe Albums in {bandChoice} are:");
                        foreach (var album in context.Albums.Where(band => band.BandSelected.Name.ToLower() == bandChoice))
                        {
                            Console.WriteLine(album.Title);
                        }
                        break;

                    case "albums in genre":
                        var genreChoice = ReadInput("What genre are you looking for?\n");

                        var albumsInGenre = context.Albums.Where(genre => genre.BandSelected.Style.ToLower() == genreChoice);
                        if (albumsInGenre != null)
                        {
                            Console.WriteLine($"\nThe Albums in {genreChoice} are:");
                            foreach (var album in albumsInGenre)
                            {
                                Console.WriteLine(album.Title);
                            }
                        }
                        // if (albumsInGenre == null)
                        // {
                        //     Console.WriteLine($"I am sorry we dont have any albums in the genre {genreChoice}");
                        // }

                        break;

                    case "members in band":
                        var bandNameChoice = ReadInput("What band are you looking for?");


                        Console.WriteLine($"\nThe members in {bandNameChoice} are:\n");
                        foreach (var band in context.Bands.Where(band => band.Name.ToLower() == bandNameChoice).Include(band => band.BandMembers).ThenInclude(name => name.Musician))
                        {
                            foreach (var musician in band.BandMembers)
                            {
                                Console.WriteLine($"{musician.Musician.FullName}");
                            }
                        }
                        break;
                    }
                    break;

                case "current clients":
                    var contractStatus = ReadInput("Would you like to see signed bands or not signed?");

                    if (contractStatus == "signed")
                    {
                        Console.WriteLine("\n");
                        Console.WriteLine("Signed Bands:");
                        foreach (var signed in context.Bands.Where(band => band.IsSigned == true))
                        {
                            Console.WriteLine(signed.Name);
                        }
                    }
                    else if (contractStatus == "not signed")
                    {
                        Console.WriteLine("\n");
                        Console.WriteLine("Not Signed Bands:");
                        foreach (var notSigned in context.Bands.Where(band => band.IsSigned == false))
                        {
                            Console.WriteLine(notSigned.Name);
                        }
                    }
                    else
                    {
                        Console.WriteLine("I am sorry, your enter is invalid");
                    }

                    break;

                case "add":

                    Console.WriteLine("\n");
                    Console.WriteLine("Add Menu:");
                    Console.WriteLine("Add a new Band");
                    Console.WriteLine("Add Album to a Band");
                    Console.WriteLine("Add song to a Album");
                    Console.WriteLine("\n");

                    var addOptions = Console.ReadLine().ToLower().Trim();

                    if (addOptions == "add a new band")
                    {
                        var newBandName = ReadInput("What is the name of your new band?");

                        var newCountry = ReadInput("What is the Country of Origin? ");

                        var newMemberNum = int.Parse(ReadInput("How many members are in the group? "));

                        var newWebsite = ReadInput("What is the website of your band? ");

                        var newStyle = ReadInput("What style is your band? ");

                        var newSigned = bool.Parse(ReadInput("Is your band signed (true or false)? "));

                        var newContact = ReadInput("What is the contact name for your band? ");

                        var newPhone = ReadInput("What is the contact phone number? ");

                        var newBand = new Band()

                        {
                            Name               = newBandName,
                            CountryOfOrigin    = newCountry,
                            NumberOfMembers    = newMemberNum,
                            Website            = newWebsite,
                            Style              = newStyle,
                            IsSigned           = newSigned,
                            ContactName        = newContact,
                            ContactPhoneNumber = newPhone
                        };

                        context.Bands.Add(newBand);

                        context.SaveChanges();
                    }

                    if (addOptions == "add album to a band")
                    {
                        var bandName   = ReadInput("Which band would you like to add to? ");
                        var bandPicked = context.Bands.FirstOrDefault(band => band.Name.ToLower() == bandName);

                        var newTitle = ReadInput("What is the title of the album? ");

                        var newIsExplicit = bool.Parse(ReadInput("Is the album Explicit ? "));

                        var newReleaseDate = DateTime.Parse(ReadInput("What is the release date of the Album? "));

                        var newAlbum = new Album()

                        {
                            Title       = newTitle,
                            IsExplicit  = newIsExplicit,
                            ReleaseDate = newReleaseDate,
                            BandId      = bandPicked.Id
                        };

                        context.Albums.Add(newAlbum);

                        context.SaveChanges();
                    }

                    if (addOptions == "add song to a album")
                    {
                        var albumName   = ReadInput("Which album would you like to add to? ");
                        var albumPicked = context.Albums.FirstOrDefault(album => album.Title.ToLower() == albumName);

                        var newTrackNumber = int.Parse(ReadInput("What is the track of the song you would like to add? "));

                        var newTitle = ReadInput("What the title of the song? ");

                        var newDuration = int.Parse(ReadInput("How long is the song? "));

                        var newSong = new Song()

                        {
                            Title       = newTitle,
                            TrackNumber = newTrackNumber,
                            Duration    = newDuration,
                            AlbumId     = albumPicked.Id
                        };

                        context.Songs.Add(newSong);

                        context.SaveChanges();
                    }

                    break;

                case "change contract":

                    Console.WriteLine("\n");
                    Console.WriteLine("Current Client Menu:");
                    Console.WriteLine("\n");
                    Console.WriteLine("Resign a Band");
                    Console.WriteLine("Let a Band go");
                    Console.WriteLine("\n");

                    var contractOptions = Console.ReadLine().ToLower().Trim();

                    if (contractOptions == "resign a band")
                    {
                        var bandToResign = ReadInput("Which band do you want to resign? ");

                        var resignBand = context.Bands.FirstOrDefault(band => band.Name.ToLower() == bandToResign);
                        if (resignBand != null)
                        {
                            resignBand.IsSigned = true;
                            context.SaveChanges();
                        }
                        else
                        {
                            Console.WriteLine("Sorry your band name was not found");
                        }
                    }

                    if (contractOptions == "let a band go")
                    {
                        var bandToLetGo = ReadInput("Which band do you want to let go?");

                        var letGoBand = context.Bands.FirstOrDefault(band => band.Name.ToLower() == bandToLetGo);
                        if (letGoBand != null)
                        {
                            letGoBand.IsSigned = true;
                            context.SaveChanges();
                        }
                        else
                        {
                            Console.WriteLine("Sorry your band name was not found");
                        }
                    }

                    break;

                case "quit":
                    userChoice = true;

                    break;
                }
            }
            Greeting("Thank you for visiting Rhythms Gonna Get You Records");
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var context       = new RhythmsGonnaGetYouContext();
            var bands         = context.Bands;
            var albums        = context.Albums.Include(a => a.Band);
            var songs         = context.Songs.Include(s => s.Album);
            var musicians     = context.Musicians;
            var bandMusicians = context.BandMusicians.Include(b => b.Band).Include(m => m.Musician);
            var producers     = context.Producers;
            var songProducers = context.SongProducers.Include(w => w.Song).Include(p => p.Producer);

            var keepGoing = true;

            Console.WriteLine("Welcome to Victory Music Company");

            while (keepGoing)
            {
                Console.WriteLine();
                Console.WriteLine("What would you like to do:");
                Console.WriteLine("[A] View all bands");
                Console.WriteLine("[B] View signed bands");
                Console.WriteLine("[C] View unsigned bands");
                Console.WriteLine("[D] View albums for a band");
                Console.WriteLine("[E] View albums by release date");
                Console.WriteLine("[F] View songs for an album");
                Console.WriteLine("[G] Add a band");
                Console.WriteLine("[H] Add an album");
                Console.WriteLine("[I] Add a song");
                Console.WriteLine("[J] Let a band go");
                Console.WriteLine("[K] Resign a band");
                Console.WriteLine("[L] View members of a band");
                Console.WriteLine("[M] View albums in a genre");
                Console.WriteLine("[N] View producers");
                Console.WriteLine("[O] View songs by a producer");
                Console.WriteLine("[Q]uit");
                var menuResponse = Console.ReadLine().ToUpper();
                Console.WriteLine();

                switch (menuResponse)
                {
                case "Q":
                    Console.WriteLine("See ya!");
                    keepGoing = false;
                    break;

                case "A":
                    foreach (var band in bands)
                    {
                        Console.WriteLine($"{band.Name}");
                        Console.WriteLine($"   From {band.CountryOfOrigin}; {band.NumberOfMembers} members; {band.Style} style; website: {band.Website}; contact is {band.ContactName} at {band.ContactPhoneNumber}");
                    }
                    if (bands.Count() == 0)
                    {
                        Console.WriteLine("No bands");
                    }
                    break;

                case "B":
                    foreach (var band in bands)
                    {
                        if (band.IsSigned == true)
                        {
                            Console.WriteLine($"{band.Name}");
                            Console.WriteLine($"   From {band.CountryOfOrigin}; {band.NumberOfMembers} members; {band.Style} style; website: {band.Website}; contact is {band.ContactName} at {band.ContactPhoneNumber}");
                        }
                    }
                    break;

                case "C":
                    foreach (var band in bands)
                    {
                        if (band.IsSigned == false)
                        {
                            Console.WriteLine($"{band.Name}");
                            Console.WriteLine($"   From {band.CountryOfOrigin}; {band.NumberOfMembers} members; {band.Style} style; website: {band.Website}; contact is {band.ContactName} at {band.ContactPhoneNumber}");
                        }
                    }
                    break;

                case "D":
                    Console.WriteLine("Pick a band: ");
                    foreach (var band in bands)
                    {
                        Console.WriteLine($"{band.Name}");
                    }
                    var bandForAlbum = Console.ReadLine().ToLower();
                    Console.WriteLine();
                    var bandAlbumList = albums.Where(a => a.Band.Name.ToLower() == bandForAlbum);
                    foreach (var album in bandAlbumList)
                    {
                        Console.WriteLine($"{album.Title}");
                    }
                    if (bandAlbumList.Count() == 0)
                    {
                        Console.WriteLine("No albums");
                    }
                    break;

                case "E":
                    var albumsInOrder = albums.OrderBy(album => album.ReleaseDate);
                    foreach (var album in albumsInOrder)
                    {
                        Console.WriteLine($"{album.Title} by {album.Band.Name}");
                    }
                    break;

                case "F":
                    Console.WriteLine("Pick a band: ");
                    foreach (var band in bands)
                    {
                        Console.WriteLine($"{band.Name}");
                    }
                    var bandForSongs = Console.ReadLine().ToLower();
                    Console.WriteLine();
                    var albumList = albums.Where(a => a.Band.Name.ToLower() == bandForSongs);
                    Console.WriteLine("Pick an album");
                    foreach (var album in albumList)
                    {
                        Console.WriteLine($"{album.Title}");
                    }
                    var albumForSongs = Console.ReadLine().ToLower();
                    Console.WriteLine();
                    var songsFromAlbum = songs.Where(s => s.Album.Title.ToLower() == albumForSongs).OrderBy(s => s.TrackNumber);
                    foreach (var song in songsFromAlbum)
                    {
                        Console.WriteLine($"{song.TrackNumber}. {song.Title}");
                    }
                    if (songsFromAlbum.Count() == 0)
                    {
                        Console.WriteLine("No songs");
                    }

                    break;

                case "G":
                    // add a band
                    // Name
                    var newBandName = PromptForString("What is the band's name? ");
                    // CountryOfOrigin
                    var newBandCountry = PromptForString("What country are they from ?");
                    // NumberOfMembers
                    var newBandMembers = PromptForInt("How many members are there? ");
                    // Website
                    var newBandWebsite = PromptForString("What is their website? ");
                    // Style
                    var newBandStyle = PromptForString("What is their style? ");
                    // IsSigned
                    // ContactName
                    var newBandContactName = PromptForString("Who is their contact? ");
                    //ContactPhoneNumber
                    var newBandContactPhone = PromptForLong("What is their phone number? ");

                    var newBand = new Band
                    {
                        Name               = newBandName,
                        CountryOfOrigin    = newBandCountry,
                        NumberOfMembers    = newBandMembers,
                        Website            = newBandWebsite,
                        Style              = newBandStyle,
                        IsSigned           = true,
                        ContactName        = newBandContactName,
                        ContactPhoneNumber = newBandContactPhone
                    };
                    context.Bands.Add(newBand);
                    context.SaveChanges();

                    break;

                case "H":
                    //add an album
                    // BandId
                    var newAlbumBandName = PromptForString("What band is this for? ");
                    var newAlbumBand     = bands.First(band => band.Name.ToLower() == newAlbumBandName.ToLower());
                    var newAlbumBandId   = newAlbumBand.Id;
                    // Title
                    var newAlbumTitle = PromptForString("What is the title? ");
                    // IsExplicit
                    Console.Write("Is it explicit? Y/N ");
                    var isItExplicit    = Console.ReadLine().ToUpper();
                    var explicitContent = true;
                    if (isItExplicit == "N")
                    {
                        explicitContent = false;
                    }
                    else if (isItExplicit == "Y")
                    {
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.WriteLine("Sorry, that is not a valid answer. Entering explicit.");
                    }
                    // ReleaseDate
                    var newAlbumReleaseDate = PromptForDate("When was it released? Please enter as YYYY-MM-DD ");

                    var newAlbum = new Album
                    {
                        Title       = newAlbumTitle,
                        IsExplicit  = explicitContent,
                        ReleaseDate = newAlbumReleaseDate,
                        BandId      = newAlbumBandId
                    };
                    context.Albums.Add(newAlbum);
                    context.SaveChanges();
                    break;

                case "I":
                    // add a song
                    // AlbumId
                    var newSongAlbumTitle = PromptForString("What is album is this on? ");
                    var newSongAlbum      = albums.First(album => newSongAlbumTitle.ToLower() == album.Title.ToLower());
                    var newSongAlbumId    = newSongAlbum.Id;
                    // Title
                    var newSongTitle = PromptForString("What is the title of the song? ");
                    // TrackNumber
                    var newSongTrack = PromptForInt("What track is it? ");
                    // Duration
                    var newSongDuration = PromptForTime("How long is it? Please enter as mm:ss ");

                    var newSong = new Song
                    {
                        TrackNumber = newSongTrack,
                        Title       = newSongTitle,
                        Duration    = newSongDuration,
                        AlbumId     = newSongAlbumId
                    };
                    context.Songs.Add(newSong);
                    context.SaveChanges();
                    break;

                case "J":
                    // let a band go
                    Console.WriteLine("Which band would you like to let go?");
                    var bandToLetGo = Console.ReadLine().ToLower();
                    var goodbyeBand = bands.First(b => b.Name.ToLower() == bandToLetGo);
                    if (goodbyeBand.IsSigned == true)
                    {
                        goodbyeBand.IsSigned = false;
                        Console.WriteLine($"{goodbyeBand.Name} was let go.");
                    }
                    else
                    {
                        Console.WriteLine("Band already not signed.");
                    }
                    break;

                case "K":
                    //resign a band
                    Console.WriteLine("Which band would you like to resign?");
                    var bandToResign = Console.ReadLine().ToLower();
                    var welcomeBack  = bands.FirstOrDefault(b => b.Name.ToLower() == bandToResign);
                    if (welcomeBack.IsSigned == false)
                    {
                        welcomeBack.IsSigned = true;
                        Console.WriteLine($"{welcomeBack.Name} was resigned.");
                    }
                    else
                    {
                        Console.WriteLine("Band was already signed.");
                    }
                    break;

                case "L":
                    //view members of band
                    Console.WriteLine("Pick a band");
                    Console.WriteLine();
                    foreach (var band in bands)
                    {
                        Console.WriteLine(band.Name);
                    }
                    var bandForMembers = Console.ReadLine().ToLower();
                    var thisBandName   = bands.First(b => b.Name.ToLower() == bandForMembers);
                    var membersOfBand  = bandMusicians.Where(x => x.BandId == thisBandName.Id);
                    Console.WriteLine();

                    foreach (var member in membersOfBand)
                    {
                        Console.WriteLine(member.Musician.Name + " on " + member.Musician.Instrument);
                    }
                    if (membersOfBand.Count() == 0)
                    {
                        Console.WriteLine("There are no members in the system.");
                    }
                    break;

                case "M":
                    //view albums by genre
                    var genre       = PromptForString("What genre would you like to view? ");
                    var genreAlbums = albums.Where(album => album.Band.Style.ToLower() == genre.ToLower());
                    foreach (var album in genreAlbums)
                    {
                        Console.WriteLine(album.Title + " by " + album.Band.Name);
                    }
                    if (genreAlbums.Count() == 0)
                    {
                        Console.WriteLine($"There are no {genre} albums.");
                    }
                    break;

                case "N":
                    // show producers
                    Console.WriteLine("Producers:");
                    foreach (var aProducer in producers)
                    {
                        Console.WriteLine(aProducer.Name);
                    }
                    break;

                case "O":
                    //show songs by producer
                    var producerName = PromptForString("Which producers do you want to see? ");
                    var theSongs     = songProducers.Where(pleasework => pleasework.Producer.Name.ToLower() == producerName.ToLower());

                    foreach (var someSong in theSongs)
                    {
                        Console.WriteLine(someSong.Song.Title);
                    }
                    break;

                default:
                    Console.WriteLine("Sorry, I don't understand. Please try again.");
                    break;
                }
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var context = new RhythmsGonnaGetYouContext();
            var albums  = context.Albums.Include(album => album.Band);
            var bands   = context.Bands;
            var quit    = false;

            while (quit != true)
            {
                Console.WriteLine("Please choose one of the following");
                Console.WriteLine();
                Console.WriteLine("Add : Add a new band");
                Console.WriteLine("View: View all the bands");
                Console.WriteLine("New: Add an album for a band");
                Console.WriteLine("Let: Let a band go");
                Console.WriteLine("Resign: Resign a band");
                Console.WriteLine("Prompt: Prompt for a band name and view all their albums");
                Console.WriteLine("VD: View all albums ordered by ReleaseDate");
                Console.WriteLine("VA: View all bands that are signed");
                Console.WriteLine("VNS: View all bands that are not signed");
                Console.WriteLine("Quit: Quit the program");
                var choice = Console.ReadLine().ToLower();
                switch (choice)
                {
                case "quit":
                    Console.WriteLine("===Good bye===");
                    quit = true;
                    break;

                case "add":
                    Console.Write("Band name: ");
                    var bandName = Console.ReadLine();
                    Console.Write("Country of origin: ");
                    var origin = Console.ReadLine();
                    Console.Write("Number of band members: ");
                    var membersNumber = int.Parse(Console.ReadLine());
                    Console.Write("Band's website: ");
                    var website = Console.ReadLine();
                    Console.Write("Band's Style: ");
                    var style = Console.ReadLine();
                    Console.Write("Is the band signed? True|False: ");
                    var isSigned = Boolean.Parse(Console.ReadLine().ToLower());
                    Console.Write("Is the band has a contact name? True|False : ");
                    var    response     = Console.ReadLine().ToLower();
                    string contactName  = null;
                    string contactPhone = null;
                    if (response == "yes")
                    {
                        Console.Write("Contact name: ");
                        contactName = Console.ReadLine();
                        Console.Write("Contact phone: ");
                        contactPhone = Console.ReadLine();
                    }
                    var newBand = new Band
                    {
                        Name               = bandName,
                        CountryOfOrigin    = origin,
                        NumberOfMembers    = membersNumber,
                        Website            = website,
                        Style              = style,
                        IsSigned           = isSigned,
                        ContactName        = contactName,
                        ContactPhoneNumber = contactPhone
                    };
                    bands.Add(newBand);
                    context.SaveChanges();
                    Console.WriteLine();
                    Console.WriteLine("Your band has been added successfully");
                    break;

                case "view":
                    foreach (var band in bands)
                    {
                        Console.WriteLine(band.Name);
                    }
                    break;

                case "new":
                    Console.Write("What is the album name? Answer: ");
                    var albumName = Console.ReadLine();
                    Console.Write("what is the band Id? Answer: ");
                    var bandId = int.Parse(Console.ReadLine());
                    Console.Write("Is this album explicit? True|False: ");
                    var isExplicit = Boolean.Parse(Console.ReadLine());
                    Console.Write("What is the release date of that album? example format: Jan 1, 2005 Answer: ");
                    var date     = DateTime.Parse(Console.ReadLine());
                    var newAlbum = new Album
                    {
                        Title       = albumName,
                        IsExplicit  = isExplicit,
                        ReleaseDate = date,
                        BandId      = bandId
                    };
                    context.Albums.Add(newAlbum);
                    context.SaveChanges();
                    Console.WriteLine("Your album has been Added successfully");
                    break;

                case "let":
                    Console.Write("What is the band name you want to let go? Answer: ");
                    var bandNameToLet = Console.ReadLine();
                    var bandToLet     = context.Bands.FirstOrDefault(band => band.Name == bandNameToLet);
                    if (bandToLet != null)
                    {
                        bandToLet.IsSigned = false;
                        context.SaveChanges();
                        Console.WriteLine("The band you entered has been let go successfully");
                    }
                    else
                    {
                        Console.WriteLine("There is no such band in the database");
                    }
                    break;

                case "Resign":
                    Console.Write("What is the band name you want to resign? Answer: ");
                    var bandNameToResign = Console.ReadLine();
                    var bandToResign     = context.Bands.FirstOrDefault(band => band.Name == bandNameToResign);
                    if (bandToResign != null)
                    {
                        bandToResign.IsSigned = true;;
                        context.SaveChanges();
                        Console.WriteLine("The band you entered has been Resigned successfully");
                    }
                    else
                    {
                        Console.WriteLine("There is no such band in the database");
                    }
                    break;

                case "prompt":
                    Console.Write("What is the band Id? Answer: ");
                    var bandIdToView = int.Parse(Console.ReadLine());
                    var albumsToView = albums.Where(album => album.Band.Id == bandIdToView);
                    foreach (var album in albumsToView)
                    {
                        Console.WriteLine(album.Title);
                    }
                    break;

                case "vd":
                    var orderedAlbums = albums.OrderBy(album => album.ReleaseDate);
                    foreach (var album in orderedAlbums)
                    {
                        Console.WriteLine($"Album {album.Title} was released on {album.ReleaseDate}");
                    }
                    break;

                case "va":
                    var signedBands = bands.Where(band => band.IsSigned == true);
                    foreach (var signedBand in signedBands)
                    {
                        Console.WriteLine(signedBand.Name);
                    }
                    break;

                case "vns":
                    var nonSignedBands = bands.Where(band => band.IsSigned == false);
                    foreach (var nonSignedBand in nonSignedBands)
                    {
                        Console.WriteLine(nonSignedBand.Name);
                    }
                    break;

                default:
                    Console.WriteLine("Invalid Entry, please try again");
                    break;
                }
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var context = new RhythmsGonnaGetYouContext();

            var userHasChosenToExit = false;

            while (userHasChosenToExit == false)
            {
                BannerMessage("~~~~~~ CH RECORDS ~~~~~~");
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("MENU OPTIONS:");
                Console.WriteLine("ARTISTS - View all signed artists.");
                Console.WriteLine("ADD ARTIST - Add a new artist.");
                Console.WriteLine("ALBUMS - View all albums.");
                Console.WriteLine("ADD ALBUM - Add a new album.");
                Console.WriteLine("SONGS - View all songs.");
                Console.WriteLine("ADD SONGS - Add a new song.");
                Console.WriteLine("UNSIGNED - View any unsigned artist and sign one to CH Records.");
                Console.WriteLine("RELEASE - Release an artist.");
                Console.WriteLine("EXIT - Exit the application.");
                Console.WriteLine();
                Console.WriteLine("Please chose one.");
                var choice = Console.ReadLine().ToUpper().Trim();
                if (choice == "EXIT")
                {
                    userHasChosenToExit = true;
                }
                switch (choice)

                {
                case "ARTISTS":

                    //show all the artists by name and show all the info assoctiated with that artist.
                    var viewArtists = context.Artists.Where(Artist => Artist.IsSigned);
                    viewArtists.OrderBy(artistOrder => artistOrder.Name);
                    Console.WriteLine();
                    Console.WriteLine("Here are all our artists!");
                    Console.WriteLine();

                    foreach (var artist in viewArtists)
                    {
                        Console.WriteLine($"{artist.Name}");
                    }
                    break;


                case "ADD ARTIST":


                    var newArtist = new Artist();
                    Console.WriteLine();
                    Console.WriteLine("What's the name of the new artist?");
                    var userAddsArtist = Console.ReadLine();
                    Console.WriteLine($"Where is {userAddsArtist}from?");
                    var userAddsCountry = Console.ReadLine();
                    Console.WriteLine($"How many members are with {userAddsArtist}?");
                    var userAddsMembers = int.Parse(Console.ReadLine());
                    Console.WriteLine("What is their website?");
                    var userAddsWebsite = Console.ReadLine();
                    Console.WriteLine($"Is {userAddsArtist} signed?");
                    var userSigned = Console.ReadLine();
                    if (userSigned == "yes")
                    {
                        newArtist.IsSigned = true;
                    }
                    else
                    {
                        newArtist.IsSigned = false;
                    }
                    Console.WriteLine($"Can I get a contact name for {userAddsArtist}?");
                    var userContactName = Console.ReadLine();
                    Console.WriteLine($"Can I also get a contact phone number for {userAddsArtist}");
                    var userContactPhone = Console.ReadLine();
                    Console.WriteLine($"Lastly, what is {userAddsArtist}'s style?");
                    var userStyle = Console.ReadLine();
                    Console.WriteLine($"Thank you for adding {userAddsArtist} to CH Records!");

                    newArtist.Name               = userAddsArtist;
                    newArtist.CountryOfOrigin    = userAddsCountry;
                    newArtist.NumberOfMembers    = userAddsMembers;
                    newArtist.Website            = userAddsWebsite;
                    newArtist.ContactName        = userContactName;
                    newArtist.ContactPhoneNumber = userContactPhone;
                    newArtist.Style              = userStyle;

                    context.Artists.Add(newArtist);
                    context.SaveChanges();

                    break;


                // case "ARTIST ALBUMS":
                // // capture a string
                // // compare a list of strings to the list of Artist
                // // look albums that this artist can contain
                // // build upon that

                // var artistAndAlbums = context.Artists.FirstOrDefault(artist => artist.Name);
                // Console.WriteLine();
                // Console.WriteLine("Which artist are you looking for?");
                // var userInput = Console.ReadLine();


                case "ALBUMS":

                    var viewAlbums = context.Albums.Include(Album => Album.Artist);
                    viewAlbums.OrderBy(albumsDate => albumsDate.ReleaseDate);
                    Console.WriteLine();
                    Console.WriteLine("This is our collection of albums!");
                    Console.WriteLine();
                    foreach (var album in viewAlbums)
                    {
                        Console.WriteLine($" {album.Title} created by {album.Artist.Name}");
                        if (album.IsExplicit)
                        {
                            Console.WriteLine(" PARENTAL ADVISORY: Explicit");
                            Console.WriteLine();
                        }
                        else
                        {
                            Console.WriteLine(" Not Explicit");
                            Console.WriteLine();
                        }
                    }



                    break;

                case "ADD ALBUM":

                    var newAlbum = new Album();
                    Console.WriteLine();
                    Console.WriteLine("What is the name of the new album?");
                    var albumName = Console.ReadLine();
                    Console.WriteLine($"Is {albumName} explict?");
                    var albumExplicit = Console.ReadLine();
                    if (albumExplicit == "yes")
                    {
                        newAlbum.IsExplicit = true;
                    }
                    else
                    {
                        newAlbum.IsExplicit = false;
                    }
                    Console.WriteLine($"When was {albumName} released? ");
                    var albumReleased = Console.ReadLine();
                    Console.WriteLine($"Who is the {albumName} by?");
                    var newAlbumArtist = context.Artists.FirstOrDefault(artist => artist.Name == Console.ReadLine());

                    newAlbum.Title       = albumName;
                    newAlbum.ReleaseDate = albumReleased;
                    newAlbum.ArtistId    = newAlbumArtist.Id;

                    context.Albums.Add(newAlbum);
                    context.SaveChanges();


                    break;

                case "SONGS":

                    var allSongs = context.Songs.Include(song => song.Album).ThenInclude(Album => Album.Artist);
                    Console.WriteLine();
                    Console.WriteLine("Here are all your songs!");
                    Console.WriteLine();
                    foreach (var song in allSongs)
                    {
                        Console.WriteLine($" Song title: {song.Title} ");
                        Console.WriteLine($" Artist: {song.Album.Artist.Name} ");
                        Console.WriteLine($" Album: { song.Album.Title} ");
                        Console.WriteLine();
                    }


                    break;


                case "ADD SONGS":

                    var newAddedSong = new Song();
                    Console.WriteLine();
                    Console.WriteLine("Can I get the title of the new song?");
                    var newTitle = Console.ReadLine();
                    Console.WriteLine($"How long is {newTitle}?");
                    var newDuration = Console.ReadLine();
                    Console.WriteLine("What is the tracknumber?");
                    var newTrackNumber = int.Parse(Console.ReadLine());
                    Console.WriteLine($"Which album does {newTitle} belong to?");
                    var newSongAlbum = context.Albums.FirstOrDefault(Album => Album.Title == Console.ReadLine());


                    newAddedSong.Title       = newTitle;
                    newAddedSong.Duration    = newDuration;
                    newAddedSong.TrackNumber = newTrackNumber;
                    newAddedSong.AlbumId     = newSongAlbum.Id;


                    context.Songs.Add(newAddedSong);
                    context.SaveChanges();


                    break;

                case "UNSIGNED":
                    // var unsignedArtist = new Artist();
                    var viewUnsignedArtists = context.Artists.Where(Artist => Artist.IsSigned == false);
                    Console.WriteLine();
                    Console.WriteLine("Please choose one of the artist below to sign!");
                    Console.WriteLine();
                    foreach (var artist in viewUnsignedArtists)
                    {
                        Console.WriteLine($"{artist.Name}");
                        Console.WriteLine();
                    }
                    var userArtist     = Console.ReadLine();
                    var resignedArtist = context.Artists.FirstOrDefault(Artist => Artist.Name == userArtist);
                    resignedArtist.IsSigned = true;
                    context.SaveChanges();

                    break;

                case "RELEASE":

                    Console.WriteLine("What is the artist name you would like to release?");
                    var releasedName   = Console.ReadLine();
                    var existingArtist = context.Artists.FirstOrDefault(Artist => Artist.Name == releasedName);
                    existingArtist.IsSigned = false;
                    context.SaveChanges();

                    break;


                default:
                    break;
                }


                BannerMessage("~~~~~~ Thanks for visiting CH Records! ~~~~~~");
            }
        }