예제 #1
0
        public IActionResult Index(int productPage, int PageSize = 5, int CategoryId = 0)
        {
            int countryId = 1;

            if (Request.Cookies["Contry"] != null)
            {
                countryId = Convert.ToInt32(Request.Cookies["Contry"]);
            }
            var products   = _productRepository.GetProductByContry(countryId, CategoryId);
            var category   = _categoriesRepository.GetCategories();
            var CategoryVM = new List <CategoryViewModel>();

            foreach (var item in category)
            {
                if (Request.Cookies["Language"] == "ar")
                {
                    var CategoryViewModel = new CategoryViewModel()
                    {
                        Id = item.Id, Name = item.NameAr
                    };
                    CategoryVM.Add(CategoryViewModel);
                }
                else
                {
                    var CategoryViewModel = new CategoryViewModel()
                    {
                        Id = item.Id, Name = item.NameEn
                    };
                    CategoryVM.Add(CategoryViewModel);
                }
            }
            StringBuilder param = new StringBuilder();

            param.Append("/Product?productPage=:");
            var count     = products.Count();
            var Countries = _countryRepository.GetCountries();
            List <CountryVM> CountriesList = new List <CountryVM>();

            foreach (var item in Countries)
            {
                CountryVM country = new CountryVM();
                if (Request.Cookies["Language"] == "en")
                {
                    country.Id = item.Id; country.Name = item.NameEn;
                }
                else
                {
                    country.Id = item.Id; country.Name = item.NameAr;
                }
                CountriesList.Add(country);
            }
            ListProductVM           listPorductVM = new ListProductVM();
            List <ProductViewModel> ListProducts  = new List <ProductViewModel>();

            foreach (var item in products)
            {
                var ProductPictuer       = _productRepository.GetProductPictuerById(item.Id);
                var ProductSpecification = _productRepository.GetProductSpecification(item.Id);
                if (Request.Cookies["Language"] == "en")
                {
                    ProductViewModel product = new ProductViewModel()
                    {
                        Id = item.Id, CategoryId = item.CategoryId, Contry = countryId, Name = item.NameEn, Description = item.DescreptionEn, PictuerUrl = ProductPictuer.Image, Price = ProductSpecification.Price
                    }; ListProducts.Add(product);
                }
                else
                {
                    ProductViewModel product = new ProductViewModel()
                    {
                        Id = item.Id, CategoryId = item.CategoryId, Contry = countryId, Name = item.NameAr, Description = item.DescreptionAr, PictuerUrl = ProductPictuer.Image, Price = ProductSpecification.Price
                    }; ListProducts.Add(product);
                }
            }
            listPorductVM.ProductViewModel = ListProducts;
            listPorductVM.Categories       = CategoryVM;
            listPorductVM.Countries        = CountriesList;
            listPorductVM.PagingInfo       = new PagingInfo {
                CurrentPage = productPage, ItemsPerPage = PageSize, TotalItems = count, urlParam = param.ToString()
            };
            listPorductVM.ProductViewModel = listPorductVM.ProductViewModel.OrderBy(x => x.Name).Skip((productPage - 1) * PageSize)
                                             .Take(PageSize).ToList();
            return(View(listPorductVM));
        }
예제 #2
0
 public HomeVM()
 {
     _listProductVM = new ListProductVM();
 }