Пример #1
0
        public void AddShow(Show show)
        {
            try
            {
                if (!File.Exists("shows.csv"))
                {
                    throw new FileNotFoundException();
                }
            }
            catch (FileNotFoundException) {
                System.Console.WriteLine("File was not found!");
                System.Console.WriteLine("Want to create the show.csv? y/n");
                string wantNewFile = Console.ReadLine();

                //creates file for user if they want it
                if (wantNewFile.Equals("y"))
                {
                    filePath = "shows.csv";
                    StreamWriter sw = new StreamWriter(filePath, true);
                }
            }
            try
            {
                // iterate through each show obj until theres no more greater, then add one
                show.showId = Shows.Max(s => s.showId) + 1;
                StreamWriter sw = new StreamWriter(filePath, true);

                sw.WriteLine($"ID: {show.showId}, Title: {show.showTitle}, Season{show.showSeason} Ep. {show.showEpisode}, Writers: {string.Join(", ", show.showWriters)}");

                sw.Close();

                // add show details to Lists
                Shows.Add(show);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }