예제 #1
0
        /// <summary>
        /// uses the Get mehod to retreive information from an API
        /// </summary>
        /// <param name="table"> the table who's API is being called</param>
        private static void getAPICall(string table)
        {
            Console.WriteLine("");
            Console.WriteLine("Which " + table + " do you wish to view?");
            Console.WriteLine("(enter '0' to view all)");
            string choice = Console.ReadLine();

            if (table.Equals("songs"))
            {
                SongsController cont = new SongsController();
                if (choice.Equals("0"))
                {
                    List <SongsModel> songs = cont.GetAllSongs();
                    foreach (SongsModel song in songs)
                    {
                        Console.WriteLine("");
                        Console.WriteLine(song.sId);
                        Console.WriteLine(song.sName);
                        Console.WriteLine(song.aName);
                        Console.WriteLine(song.year);
                    }
                }
                else
                {
                    SongsModel song = cont.GetSongById(choice);
                    if (song != null)
                    {
                        Console.WriteLine("");
                        Console.WriteLine(song.sId);
                        Console.WriteLine(song.sName);
                        Console.WriteLine(song.aName);
                        Console.WriteLine(song.year);
                    }
                    else
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Not Found.");
                    }
                }
            }
            else if (table.Equals("reviews"))
            {
                ReviewsController cont = new ReviewsController();
                if (choice.Equals("0"))
                {
                    List <ReviewsModel> revs = cont.GetAllReviews();
                    foreach (ReviewsModel rev in revs)
                    {
                        Console.WriteLine("");
                        Console.WriteLine(rev.rId);
                        Console.WriteLine(rev.sId);
                        Console.WriteLine(rev.sRating);
                        Console.WriteLine(rev.textReview);
                    }
                }
                else
                {
                    ReviewsModel rev = cont.GetReviewById(choice);

                    if (rev != null)
                    {
                        Console.WriteLine("");
                        Console.WriteLine(rev.rId);
                        Console.WriteLine(rev.sId);
                        Console.WriteLine(rev.sRating);
                        Console.WriteLine(rev.textReview);
                    }
                    else
                    {
                        Console.WriteLine("");
                        Console.WriteLine("Not Found.");
                    }
                }
            }
        }