Пример #1
0
        /// <summary>
        /// This method allows us to set each line's information into titles
        /// </summary>
        public void SetResults()
        {
            // debug delete later
            Console.WriteLine(SearchedType);
            Console.WriteLine(SearchedWord);
            Console.WriteLine(SearchedStartYear);
            Console.WriteLine(SearchedIfAdult);
            Console.WriteLine(SearchedEndYear);
            if (SearchedGenres != null)
            {
                foreach (string genre in SearchedGenres)
                {
                    Console.WriteLine(genre);
                }
            }
            Console.WriteLine(SearchedRating);


            // this IEnumerable lets us find titles by the given parametes
            IEnumerable <Title> findTitles = new List <Title>();

            // checks if searched word is valid and filters
            if (SearchedWord != "N/A")
            {
                findTitles =
                    (from title in TitlesInFile
                     where (title.TitleName).ToLower()
                     .Contains(SearchedWord.ToLower())
                     select title);
            }

            // checks if searched type is valid and filters
            if (SearchedType != "N/A")
            {
                findTitles =
                    (from title in findTitles
                     where (title.Type).ToLower().Contains(SearchedType.ToLower())
                     select title);
            }

            // checks if searched start year is valid and filters
            if (SearchedStartYear != "N/A")
            {
                findTitles =
                    (from title in findTitles
                     where (title.StartYear.ToLower()
                            .Equals(SearchedStartYear.ToLower()))
                     select title);
            }
            // checks if searched end year is valid and filters
            if (SearchedEndYear != "N/A")
            {
                findTitles =
                    (from title in findTitles
                     where (title.EndYear.ToLower()
                            .Equals(SearchedEndYear.ToLower()))
                     select title);
            }

            // checks if adult is valid and filters
            if (SearchedIfAdult != "N/A")
            {
                findTitles =
                    (from title in findTitles
                     where (title.Adult).ToLower().
                     Contains(SearchedIfAdult.ToLower())
                     select title);
            }

            // checks genres to see if any is valid and filters
            if (SearchedGenres != null)
            {
                foreach (string genre in SearchedGenres)
                {
                    if (genre != "N/A")
                    {
                        findTitles =
                            (from title in findTitles
                             where (title.Genres.Contains(genre))
                             select title);
                    }
                }
            }

            // checks ratings and filters
            if (SearchedRating != "N/A")
            {
                findTitles =
                    (from title in findTitles
                     where (title.Rating).Equals(SearchedRating.ToLower())
                     select title);
            }

            // set organized titles to list
            OrganizedTitles = findTitles.ToList();

            OrganizedTitles[1].WriteInfo();

            for (int i = 0; i < 30; i++)
            {
                (OrganizedTitles)[i + 1].WriteInfo();
            }

            // remove duplicates from the list
            OrganizedTitles = OrganizedTitles.GroupBy(s => s)
                              .Where(g => g.Count() > 0)
                              .Select(g => g.Key).ToList();

            // send to sort and print
            ResultsSorters.ResultSetter(OrganizedTitles);
            ScreenPrints.SortResults(OrganizedTitles);

            // clear titles in file list for memory saving
            TitlesInFile.Clear();
        }
Пример #2
0
        public static void SortResults(List <Title> titlesToSort)
        {
            Console.WriteLine("\t\t\t        Sort titles\n");
            Console.WriteLine("\t\t\t  To sort items in list, select a number ");

            Console.WriteLine("\t\t\t  1 - Sort by Type");

            Console.WriteLine("\t\t\t  2 - Sort by Title");

            Console.WriteLine("\n\t\t\t  3 - Sort by Start Year");

            Console.WriteLine("\n\t\t\t  4 - Sort by End Year");

            Console.WriteLine("\n\t\t\t  5 - Sort by Adult Rating.");

            Console.WriteLine("\n\t\t\t  6 - Sort by Title Rating.");


            Console.WriteLine("\n\n\t\t\t   Please enter your search");
            Console.WriteLine("\n\n\n\n\n\n\n");
            Console.Write("\t\t\t>> ");

            //This try-catch was created to filter the System.Format Exception
            //However, it was kept generic to look out for an untested Exception
            //or one that wasn't forseen to happen.
            try
            {
                input = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("\n\t\t\t   >> Invalid input <<\n");
                OtherSearch();
            }

            //Do-while cycle to keep on asking for these options until there's a
            //cycle break.
            do
            {
                switch (input)
                {
                case 1:
                    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                    ResultsSorters.SortByTitle(titlesToSort);
                    break;

                case 2:
                    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                    ResultsSorters.SortByType(titlesToSort);
                    break;

                case 3:
                    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                    ResultsSorters.SortByStartYear(titlesToSort);
                    break;

                case 4:
                    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                    ResultsSorters.SortByEndYear(titlesToSort);
                    break;

                case 5:
                    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                    ResultsSorters.SortByAdultRating(titlesToSort);
                    break;

                case 6:
                    Console.Write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                    ResultsSorters.SortByRating(titlesToSort);
                    break;

                default:
                    Console.WriteLine("\t\t\t   >> Invalid input <<\n");
                    OtherSearch();
                    break;
                }
            } while (input <= 0 || input >= 6);
        }