예제 #1
0
        static void Main(string[] args)
        {
            string inputLine = "";

            RequestConsumer reqConsumer = new RequestConsumer(baseUrl);

            while (true)
            {
                PrintMenu();
                inputLine = Console.ReadLine().ToLower();

                if (inputLine == "4")
                {
                    break;
                }

                ExecuteMenuChoice(inputLine, reqConsumer);

                PrintEndOperationsCycle();
            }
        }
예제 #2
0
        private static string EnterAlbum(RequestConsumer reqConsumer, string controller)
        {
            Console.WriteLine("Enter title: ");
            string title = Console.ReadLine();

            Console.WriteLine("Enter producer(optional): ");
            string producer = Console.ReadLine();

            Console.WriteLine("Enter release date(optional): ");
            DateTime?releaseDate = null;

            try
            {
                releaseDate = DateTime.Parse(Console.ReadLine());
            }
            catch (FormatException ex)
            {
            }

            Album newAlbum = new Album()
            {
                Title       = title,
                Producer    = producer,
                ReleaseDate = releaseDate,
            };

            Console.WriteLine("As Json(1) Or XML(2)? ");
            string choice = Console.ReadLine();

            if (choice == "1")
            {
                var sent = reqConsumer.CreateAsJson <Album>(newAlbum, controller);
                return(sent);
            }
            else
            {
                var sent = reqConsumer.CreateAsXML <Album>(newAlbum, controller);
                return(sent);
            }
        }
예제 #3
0
        private static string UpdateSong(RequestConsumer reqConsumer, string controller)
        {
            Console.Write("Enter id: ");
            var inputId = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter title: ");
            string title = Console.ReadLine();

            Console.WriteLine("Enter genre(optional): ");
            string genre = Console.ReadLine();

            Console.WriteLine("Enter release date(optional): ");
            DateTime?releaseDate = null;

            try
            {
                releaseDate = DateTime.Parse(Console.ReadLine());
            }
            catch (FormatException ex)
            {
            }

            MusicStoreContext db = new MusicStoreContext();

            Console.WriteLine("Artist Name(optional): ");
            string artistName = Console.ReadLine();



            var artist = (Artist)(from a in db.Artists
                                  where a.Name == artistName
                                  select a
                                  ).FirstOrDefault();
            Song newSong;

            if (artist == null)
            {
                newSong = new Song()
                {
                    SongId = inputId,
                    Title  = title,
                    Genre  = genre,
                    Year   = releaseDate
                };
            }
            else
            {
                newSong = new Song()
                {
                    SongId = inputId,
                    Title  = title,
                    Genre  = genre,
                    Year   = releaseDate,
                    Artist = CreateArtistObject(artist.ArtistId, artist.Name, artist.Country, artist.DateOfBirth)
                };
            }

            Console.WriteLine("As Json(1) Or XML(2)? ");
            string choice = Console.ReadLine();

            if (choice == "1")
            {
                var sent = reqConsumer.UpdateAsJson <Song>(newSong, controller, inputId.ToString());
                return(sent);
            }
            else
            {
                var sent = reqConsumer.UpdateAsXML <Song>(newSong, controller, inputId.ToString());
                return(sent);
            }
        }
예제 #4
0
        private static string UpdateAlbum(RequestConsumer reqConsumer, string controller)
        {
            Console.Write("Enter id: ");
            var inputId = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter title: ");
            string title = Console.ReadLine();

            Console.WriteLine("Enter producer(optional): ");
            string producer = Console.ReadLine();

            Console.WriteLine("Enter release date(optional): ");
            DateTime?releaseDate = null;

            try
            {
                releaseDate = DateTime.Parse(Console.ReadLine());
            }
            catch (FormatException ex)
            {
            }

            Console.WriteLine("Artist Name(optional): ");
            string artistName = Console.ReadLine();


            MusicStoreContext db = new MusicStoreContext();

            var artist = (from a in db.Artists
                          where a.Name == artistName
                          select a
                          ).ToList();

            Album newAlbum;

            if (artist == null)
            {
                newAlbum = new Album()
                {
                    AlbumId     = inputId,
                    Title       = title,
                    Producer    = producer,
                    ReleaseDate = releaseDate
                };
            }
            else
            {
                List <Artist> artists = new List <Artist>();
                foreach (var art in artist)
                {
                    artists.Add(CreateArtistObject(artist[0].ArtistId, artist[0].Name, artist[0].Country, artist[0].DateOfBirth));
                }

                newAlbum = new Album()
                {
                    AlbumId     = inputId,
                    Title       = title,
                    Producer    = producer,
                    ReleaseDate = releaseDate,
                    Artists     = artists
                };
            }

            Console.WriteLine("As Json(1) Or XML(2)? ");
            string choice = Console.ReadLine();

            if (choice == "1")
            {
                var sent = reqConsumer.UpdateAsJson <Album>(newAlbum, controller, inputId.ToString());
                return(sent);
            }
            else
            {
                var sent = reqConsumer.UpdateAsXML <Album>(newAlbum, controller, inputId.ToString());
                return(sent);
            }
        }