示例#1
0
        public IActionResult Index()
        {
            var merchants = _merchantRepository.GetAll();
            var mapped    = _mapper.Map <List <MerchantViewModel> >(merchants);

            return(View(mapped));
        }
        public IEnumerable <MerchantDto> GetAll()
        {
            var merchants = _repository
                            .GetAll()
                            .Select(AutoMapperHelper.Map <Merchant, MerchantDto>)
                            .ToList();

            return(merchants);
        }
        public IViewComponentResult Invoke()
        {
            var merchants = _merchantRepository.GetAll().Where(m => m.Products.Count > 0).OrderBy(m => m.Name).ToList();

            foreach (var merchant in merchants)
            {
                var categories = _categoryRepository.GetCategoryByMerchant(merchant);
                merchant.Categories = categories.Where(c => c.Products.Count > 0).OrderBy(c => c.Name).ToList();
            }
            var mapped = _mapper.Map <List <MerchantViewModel> >(merchants);

            return(View(mapped));
        }
示例#4
0
        public IActionResult Index(int?merchantId, int?categoryId, int?page, string search = null, string orderBy = null, int pageSize = 36)
        {
            var merchants  = new List <Merchant>();
            var categories = new List <Category>();
            var products   = new List <Product>();

            if (search != null)
            {
                search    = search.ToLower();
                merchants = _merchantRepository.GetAll();
                products  = _productRepository.GetByCondition(p => p.Name.ToLower().Contains(search) || p.Description.ToLower().Contains(search));
            }
            else
            {
                if (!merchantId.HasValue && !categoryId.HasValue)
                {
                    products = _productRepository.GetAll().OrderBy(p => p.CurrentPrice).ToList();
                }

                else if (merchantId.HasValue && (!categoryId.HasValue))
                {
                    products = _productRepository.GetProductInMerchant(merchantId.Value);
                }
                else if (merchantId.HasValue && categoryId.HasValue)
                {
                    products = _productRepository.GetProductInCategory(categoryId.Value);
                }
            }
            foreach (var product in products)
            {
                product.Merchant = _merchantRepository.GetProductMerchant(product);
                product.Category = _categoryRepository.GetProductCategory(product);
            }

            var productsView = _mapper.Map <List <ProductViewModel> >(products);
            var pages        = PagingList <ProductViewModel> .Create(productsView, page ?? 1, pageSize);

            return(View(pages));
        }
 public ActionResult <IEnumerable <Merchant> > GetAllMerchants()
 {
     return(Ok(_merchantRepository.GetAll()));
 }
示例#6
0
 public IEnumerable <MerchantViewModel> GetAll()
 {
     return(_Mapper.Map <IEnumerable <MerchantViewModel> >(_MerchantRepository.GetAll(o => o.Id != null)));
 }
        public IActionResult Index(int?merchId, int?cateId, string search = null, int pageSize = 12, int pageNo = 1)
        {
            var merchants  = new List <Merchant>();
            var categories = new List <Category>();
            var products   = new List <Product>();

            if (search != null)
            {
                search    = search.ToLower();
                merchants = _merchantRepository.GetAll();
                products  = _productRepository.GetByCondition(p => p.Name.ToLower().Contains(search) || p.Description.ToLower().Contains(search));
            }
            else
            {
                if ((!merchId.HasValue && !cateId.HasValue))
                {
                    merchants = _merchantRepository.GetAll();
                    products  = _productRepository.GetAll();
                }
                else if (merchId.HasValue && (!cateId.HasValue))
                {
                    var merchant = _merchantRepository.GetById(merchId.Value);
                    merchants.Add(merchant);
                    foreach (var item in _merchantCategoryRepo.GetCategoriesInMerchant(merchant))
                    {
                        var cate = _categoryRepository.GetById(item);
                        categories.Add(cate);//categories contain products
                    }
                    products = _productRepository.GetProductInMerchant(merchId.Value);
                }
                else if (merchId.HasValue && cateId.HasValue)
                {
                    var merchant = _merchantRepository.GetById(merchId.Value);
                    merchants.Add(merchant);
                    foreach (var item in _merchantCategoryRepo.GetCategoriesInMerchant(merchant))
                    {
                        var cate = _categoryRepository.GetById(item);
                        if (cate.Products != null)
                        {
                            categories.Add(cate); //all category doesn't contain any product
                        }
                    }
                    products = _productRepository.GetProductInCategory(cateId.Value);
                }
            }

            categories = categories.Where(c => c.Products != null).ToList();
            categories.OrderByDescending(c => c.Products.Count);
            var merchantsView  = _mapper.Map <List <MerchantViewModel> >(merchants);
            var categoriesView = _mapper.Map <List <CategoryViewModel> >(categories);
            var productsView   = _mapper.Map <List <ProductViewModel> >(products);
            var pages          = PagingList <ProductViewModel> .Create(productsView, pageNo, pageSize);

            dynamic model = new ExpandoObject();

            model.Merchants  = merchantsView;
            model.Categories = categoriesView;
            model.Products   = productsView;
            model.PageList   = pages;
            return(View(model));
        }