Exemplo n.º 1
0
        public IQueryable <Announcement> Sort(
            IQueryable <Announcement> announcementsToSort,
            SortOrderParams sortOrder,
            SortOptionsParams sortOptions,
            int?sectionId,
            int?subsectionId,
            int?categoryId)
        {
            if (categoryId.HasValue)
            {
                announcementsToSort = announcementsToSort.Where(a => a.CategoryId == categoryId.Value);
            }

            if (subsectionId.HasValue)
            {
                announcementsToSort = announcementsToSort.Where(a => a.SubsectionId == subsectionId.Value);
            }
            else if (sectionId.HasValue)
            {
                announcementsToSort = announcementsToSort.Where(a => a.SectionId == sectionId.Value);
            }

            if (sortOptions == SortOptionsParams.ByName)
            {
                announcementsToSort = sortOrder == SortOrderParams.Ascending
                    ? announcementsToSort.OrderBy(a => a.Name)
                    : announcementsToSort.OrderByDescending(a => a.Name);
            }

            if (sortOptions == SortOptionsParams.ByPrice)
            {
                announcementsToSort =
                    sortOrder == SortOrderParams.Ascending
                        ? announcementsToSort.OrderBy(a => a.Price).ThenBy(a => a.UpTime)
                        : announcementsToSort.OrderByDescending(a => a.Price).ThenByDescending(a => a.UpTime);
            }

            if (sortOptions == SortOptionsParams.ByDate)
            {
                announcementsToSort = sortOrder == SortOrderParams.Ascending
                                    ? announcementsToSort.OrderBy(a => a.UpTime)
                                    : announcementsToSort.OrderByDescending(a => a.UpTime);
            }

            return(announcementsToSort);
        }
Exemplo n.º 2
0
        public static IEnumerable <Product> Sort(this IEnumerable <Product> products, SortOrderParams sortOrder, SortOptionsParams sortOptions,
                                                 int secondCategoryId, int?thirdCategoryId)
        {
            if (thirdCategoryId.HasValue)
            {
                products = products.Where(p => p.ManufacturerID == thirdCategoryId.Value);
            }

            if (sortOrder == SortOrderParams.Ascending)
            {
                products = sortOptions == SortOptionsParams.ByName ? products.OrderBy(p => p.Title) : products.OrderBy(p => p.ShopProduct.Min(spr => spr.Price));
            }
            // Sorting by descending
            else
            {
                products = sortOptions == SortOptionsParams.ByName ? products.OrderByDescending(p => p.Title) : products.OrderByDescending(p => p.ShopProduct.Max(spr => spr.Price));
            }

            return(products);
        }
Exemplo n.º 3
0
        public static IEnumerable <ShopProduct> Sort(this IEnumerable <ShopProduct> shops, SortOrderParams sortOrder, SortOptionsParams sortOptions, bool byShop = true)
        {
            if (sortOrder == SortOrderParams.Ascending)
            {
                shops = sortOptions == SortOptionsParams.ByName ? byShop ? shops.OrderBy(p => p.Shop.Title) : shops.OrderBy(p => p.Product.Title) : shops.OrderBy(p => p.Price);
            }
            else
            {
                shops = sortOptions == SortOptionsParams.ByName ? byShop ? shops.OrderByDescending(p => p.Shop.Title) : shops.OrderByDescending(p => p.Product.Title) : shops.OrderByDescending(p => p.Price);
            }

            return(shops);
        }
Exemplo n.º 4
0
        public IQueryable <Domain.Entity.Realty.Realty> Sort(IQueryable <Domain.Entity.Realty.Realty> realty, SortOrderParams sortOrder, SortOptionsParams sortOptions, int?sectionId, int?categoryId)
        {
            if (categoryId.HasValue && categoryId.Value != 0)
            {
                realty = ReadByCategory(realty, categoryId.Value);
            }

            if (sectionId.HasValue && sectionId.Value != 0)
            {
                realty = ReadBySection(realty, sectionId.Value);
            }

            if (sortOptions == SortOptionsParams.ByName)
            {
                realty = sortOrder == SortOrderParams.Ascending
                    ? realty.OrderBy(r => r.Name)
                    : realty.OrderByDescending(r => r.Name);
            }

            if (sortOptions == SortOptionsParams.ByPrice)
            {
                realty =
                    sortOrder == SortOrderParams.Ascending
                        ? realty.OrderBy(r => r.Price)
                        : realty.OrderByDescending(r => r.Price);
            }

            if (sortOptions == SortOptionsParams.ByDate)
            {
                realty = sortOrder == SortOrderParams.Ascending
                                    ? realty.OrderBy(r => r.UpTime)
                                    : realty.OrderByDescending(r => r.UpTime);
            }

            return(realty);
        }
Exemplo n.º 5
0
        public IQueryable <Product> Sort(IQueryable <Product> products, SortOrderParams sortOrder, SortOptionsParams sortOptions,
                                         int secondCategoryId, int?thirdCategoryId)
        {
            if (thirdCategoryId.HasValue)
            {
                products = products.Where(p => p.ThirdCategoryId == thirdCategoryId.Value);
            }

            if (sortOrder == SortOrderParams.Ascending)
            {
                if (sortOptions == SortOptionsParams.ByName)
                {
                    products = products.OrderBy(p => p.Name);
                }
                else
                {
                    products = products.OrderBy(p => p.ShopProductRefs.Min(spr => spr.Price));
                }
            }
            // Sorting by descending
            else
            {
                if (sortOptions == SortOptionsParams.ByName)
                {
                    products = products.OrderByDescending(p => p.Name);
                }
                else
                {
                    products = products.OrderByDescending(p => p.ShopProductRefs.Max(spr => spr.Price));
                }
            }

            return(products);
        }