Example #1
0
        public void AddToWatchList(string[] animes, List <Anime> animeList)
        {
            foreach (var item in animes)
            {
                if (!int.TryParse(item, out int index) || index >= animeList.Count || index < 0)
                {
                    Program.DisplayError($"ERROR: INVALID INDEX: {item} PROVIDED, SO IT WON'T BE ADDED");
                    continue;
                }

                string title = animeList[index].Title;

                for (int i = title.Length - 1; i != 0; i--)
                {
                    if (title[i] == '-')
                    {
                        var animeToBeAdded = new WatchListItem()
                        {
                            Title         = title.Remove(i),
                            LatestEpisode = 0,
                            IsDownloaded  = false,
                            ReleaseDay    = animeList[index].PubDate
                        };

                        // Check if it already exists in the watchlist
                        if (WatchList.Contains(animeToBeAdded))
                        {
                            Program.DisplayError($"Anime \"{animeToBeAdded.Title}\" already exists in the watchlist");
                            break;
                        }

                        // Add a new watchlist value
                        WatchList.Add(animeToBeAdded);
                        break;
                    }
                }
            }
            // Rechecks the whole list for containing animes
            foreach (var anime in animeList)
            {
                anime.IsInWatchList = ContainsInWatchList(anime);
            }

            WatchList.Sort();
        }