コード例 #1
0
        public ViewResult UserCatalog(int page          = 1, string name = null, string category = null, string country = null, int?minYear = null, int?maxYear = null, string material = null,
                                      float?minWeight   = null, float?maxWeight = null, float?minDiameter = null, float?maxDiameter = null,
                                      string byName     = null, string byYear   = null, string byCountry  = null, string byCategory = null, string byMaterial = null, string byWeight = null, string byDiameter = null,
                                      string byDateTime = null)
        {
            ViewBag.UserAuth = User.Identity.IsAuthenticated;
            ViewBag.UserName = User.Identity.Name;
            Array.Sort(RusCountries);
            ViewBag.Countries  = RusCountries;
            ViewBag.Materials  = RusMaterials;
            ViewBag.Categories = RusCategories;


            List <Product> allProducts = db.Products.Include(c => c.UserAdder).Where(x => x.isMainCatalog == false).OrderByDescending(x => x.DateTime).ToList();

            ViewBag.CatalogCount = allProducts.Count;
            filterInformation    = new FilterInformation {
                name     = name, country = country, category = category, minYear = minYear, maxYear = maxYear,
                material = material, minWeight = minWeight, maxWeight = maxWeight, minDiameter = minDiameter, maxDiameter = maxDiameter
            };
            sortingInformation = new SortingInformation {
                byName     = byName, byCountry = byCountry, byCategory = byCategory, byYear = byYear,
                byMaterial = byMaterial, byWeight = byWeight, byDiameter = byDiameter,
                byDateTime = byDateTime
            };

            allProducts = ApplyFilter(allProducts, filterInformation);
            allProducts = ApplySorting(allProducts, sortingInformation);
            if (filterInformation.name != null)
            {
                allProducts = SearchByName(allProducts, filterInformation.name);
            }

            int pageSize = 50;

            var count = allProducts.Count();

            ViewBag.SearchCount = count;
            var              items         = allProducts.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            PageViewModel    pageViewModel = new PageViewModel(count, page, pageSize);
            CatalogViewModel viewModel     = new CatalogViewModel
            {
                PageViewModel      = pageViewModel,
                Products           = items,
                FilterInformation  = filterInformation,
                SortingInformation = sortingInformation
            };

            return(View("UserCatalog", viewModel));
        }
コード例 #2
0
        private List <Product> ApplySorting(List <Product> products, SortingInformation sorter)
        {
            if (sorter.byDiameter == "По возрастанию")
            {
                products = products.OrderBy(x => x.Diameter).ToList();
            }
            else if (sorter.byDiameter == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Diameter).ToList();
            }

            if (sorter.byWeight == "По возрастанию")
            {
                products = products.OrderBy(x => x.Weight).ToList();
            }
            else if (sorter.byWeight == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Weight).ToList();
            }

            if (sorter.byMaterial == "По возрастанию")
            {
                products = products.OrderBy(x => x.Material).ToList();
            }
            else if (sorter.byMaterial == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Material).ToList();
            }

            if (sorter.byYear == "По возрастанию")
            {
                products = products.OrderBy(x => x.Year).ToList();
            }
            else if (sorter.byYear == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Year).ToList();
            }

            if (sorter.byCategory == "По возрастанию")
            {
                products = products.OrderBy(x => x.Category).ToList();
            }
            else if (sorter.byCategory == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Category).ToList();
            }

            if (sorter.byCountry == "По возрастанию")
            {
                products = products.OrderBy(x => x.Country).ToList();
            }
            else if (sorter.byCountry == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Country).ToList();
            }

            if (sorter.byName == "По возрастанию")
            {
                products = products.OrderBy(x => x.Name).ToList();
            }
            else if (sorter.byName == "По убыванию")
            {
                products = products.OrderByDescending(x => x.Name).ToList();
            }

            if (sorter.byDateTime == "По возрастанию")
            {
                products = products.OrderBy(x => x.DateTime).ToList();
            }
            else if (sorter.byDateTime == "По убыванию")
            {
                products = products.OrderByDescending(x => x.DateTime).ToList();
            }

            return(products);
        }
コード例 #3
0
        public ViewResult AboutUser(int userId, int page = 1, string name        = null, string category   = null, string country    = null, int?minYear = null, int?maxYear = null, string material = null,
                                    float?minWeight      = null, float?maxWeight = null, float?minDiameter = null, float?maxDiameter = null,
                                    string byName        = null, string byYear   = null, string byCountry  = null, string byCategory = null, string byMaterial = null, string byWeight = null, string byDiameter = null,
                                    string byDateTime    = null)
        {
            ViewBag.UserAuth = User.Identity.IsAuthenticated;
            ViewBag.UserName = User.Identity.Name;
            Array.Sort(RusCountries);
            ViewBag.Countries  = RusCountries;
            ViewBag.Materials  = RusMaterials;
            ViewBag.Categories = RusCategories;
            User userAbout = db.Users.Include(c => c.UserProducts).ThenInclude(cs => cs.Product).FirstOrDefault(x => x.UserId == userId);

            User user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            if (user == null)
            {
                ViewBag.UserRole = "";
            }
            else
            {
                ViewBag.UserRole = user.Role;
            }

            List <Product> allProducts = userAbout.UserProducts.Select(sc => sc.Product).OrderByDescending(x => x.DateTime).ToList();

            ViewBag.CatalogCount = allProducts.Count;

            filterInformation = new FilterInformation
            {
                name        = name,
                country     = country,
                category    = category,
                minYear     = minYear,
                maxYear     = maxYear,
                material    = material,
                minWeight   = minWeight,
                maxWeight   = maxWeight,
                minDiameter = minDiameter,
                maxDiameter = maxDiameter
            };
            sortingInformation = new SortingInformation
            {
                byName     = byName,
                byCountry  = byCountry,
                byCategory = byCategory,
                byYear     = byYear,
                byMaterial = byMaterial,
                byWeight   = byWeight,
                byDiameter = byDiameter,
                byDateTime = byDateTime
            };

            allProducts = ApplyFilter(allProducts, filterInformation);
            allProducts = ApplySorting(allProducts, sortingInformation);
            if (filterInformation.name != null)
            {
                allProducts = SearchByName(allProducts, filterInformation.name);
            }

            int pageSize = 50;

            var count = allProducts.Count();

            ViewBag.SearchCount = count;
            var              items         = allProducts.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            PageViewModel    pageViewModel = new PageViewModel(count, page, pageSize);
            CatalogViewModel viewModel     = new CatalogViewModel
            {
                PageViewModel      = pageViewModel,
                Products           = items,
                FilterInformation  = filterInformation,
                SortingInformation = sortingInformation,
                User = userAbout
            };

            return(View("AboutUser", viewModel));
        }