static void Main()
        {
            var elements = new List<int>()
            {
                 40, 50, 60, 5, 10, 20, 30,
            };

            var ordered = elements.SortBy(x => x);

            Console.WriteLine(string.Join(", ", ordered));

            var students = new List<Student>()
            {
                new Student("Gosho", 20, 4.5),
                new Student("Pesho", 17, 2),
                new Student("Tanio", 23, 6.00),
                new Student("Ivan", 21, 5.5)
            };

            var goodStudents = students
                .Filter(st => st.AverageGrade > 5)
                .SortBy(st => st.Age)
                .Project(st => st.Name);

            Console.WriteLine(string.Join("\n", goodStudents));
        }
        private static void Main()
        {
            var elements = new List<int> { 40, 50, 60, 5, 10, 20, 30 };

            var ordered = elements.SortBy(x => x);

            Console.WriteLine(string.Join(", ", ordered));

            var students = new List<Student>
                               {
                                   new Student("Gosho", 20, 4.5),
                                   new Student("Pesho", 17, 2),
                                   new Student("Tanio", 23, 6.00),
                                   new Student("Ivan", 21, 5.5)
                               };

            var goodStudents = students.Filter(st => st.AverageGrade > 5).SortBy(st => st.Age).Project(st => st.Name);

            var ivan = students.FirstOrDef(st => st.Name == "Ivan");

            // var goodStudents = students.Where(st => st.AverageGrade > 5).OrederBy(st => st.Age).Select(st => st.Name); //tova e LINQ varianta na gornata zaivka
            Console.WriteLine(string.Join("\n", goodStudents));
        }
Example #3
0
        private ICollection<ProductListItem> SearchProducts(ProductFilterModel filter)
        {
            var products = new List<ProductListItem>();

            bool isSelectedAnyPlatform = filter.Platforms != null && filter.Platforms.Any(p => p.Selected);
            bool isSelectedAnyGenre = filter.Genres != null && filter.Genres.Any(p => p.Selected);
            bool isSelectedAnyPegi = filter.PegiRatings != null && filter.PegiRatings.Any(p => p.Selected);

            IEnumerable<SelectListItem> selectedPlatforms = null;
            IEnumerable<SelectListItem> selectedPegis = null;
            IEnumerable<SelectListItem> selectedGenres = null;

            if (isSelectedAnyGenre) { selectedGenres = filter.Genres.Where(p => p.Selected == true); }
            if (isSelectedAnyPegi) { selectedPegis = filter.PegiRatings.Where(p => p.Selected == true); }
            if (isSelectedAnyPlatform) { selectedPlatforms = filter.Platforms.Where(p => p.Selected == true); }

            foreach (var prod in ProductManager.Products.ToList())
            {
                if (!prod.IsDeleted && prod.Name.Contains(filter.SearchKeyword != null ? filter.SearchKeyword : string.Empty))
                {
                    if (isSelectedAnyGenre && !selectedGenres.Any(g =>
                        g.Value == prod.GenreId.ToString())) { continue; }
                    if (isSelectedAnyPlatform && !selectedPlatforms.Any(p =>
                        p.Value == prod.PlatformId.ToString())) { continue; }
                    if (isSelectedAnyPegi && !selectedPegis.Any(p =>
                        p.Value == prod.PegiRatingId.ToString())) { continue; }
                    products.Add(prod.ToListItem());
                }
            }

            return products.SortBy(filter.ProductSortType).ToList();
        }