コード例 #1
0
ファイル: HomeController.cs プロジェクト: Alekseyya/ASP.net
        public ActionResult Catalog()
        {
            IEnumerable <IndexProductViewModel> products;

            using (var client = new service.ServiceClient())
            {
                Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, IndexProductViewModel>());
                products = Mapper.Map <IEnumerable <service.ProductDataContract>, IEnumerable <IndexProductViewModel> >(client.GetProducts());
            }
            ViewBag.Products = products;
            return(View(new CategoryViewModel()));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: Alekseyya/ASP.net
        public ActionResult ProductList()
        {
            IEnumerable <IndexProductViewModel> product = null;

            using (var client = new service.ServiceClient())
            {
                Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, IndexProductViewModel>());
                product = Mapper.Map <IEnumerable <service.ProductDataContract>, IEnumerable <IndexProductViewModel> >(client.GetProducts());
            }

            return(View(product));
        }
コード例 #3
0
ファイル: CartController.cs プロジェクト: Alekseyya/ASP.net
 private CartViewModel TransformCart()
 {
     using (var client = new service.ServiceClient())
     {
         var products = client.GetProducts();
         var r        = new CartViewModel
         {
             Items = Cart.Items.ToDictionary(x => products.First(y => y.Id == x.ProductId), x => x.Count)
         };
         return(r);
     }
 }
コード例 #4
0
        public ActionResult Details(int id)
        {
            using (var client = new service.ServiceClient())
            {
                var prod = client.GetItemProduct(id);
                if (prod != null)
                {
                    return(View(prod));
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: Alekseyya/ASP.net
 public ActionResult EditProduct(EditProductViewModel product)
 {
     if (ModelState.IsValid)
     {
         using (var client = new service.ServiceClient()) //преобразовать в ProductDataContract
         {
             Mapper.Initialize(o => o.CreateMap <EditProductViewModel, service.ProductDataContract>());
             service.ProductDataContract prod = Mapper.Map <EditProductViewModel, service.ProductDataContract>(product);
             client.UpdateProduct(prod);
         }
     }
     return(RedirectToAction("Index"));
 }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: Alekseyya/ASP.net
        public ActionResult Catalog(CategoryViewModel category)
        {
            IEnumerable <IndexProductViewModel> products;

            using (var client = new service.ServiceClient())
            {
                Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, IndexProductViewModel>());
                products = Mapper.Map <IEnumerable <service.ProductDataContract>, IEnumerable <IndexProductViewModel> >(client.GetProducts());
            }
            if (category.NameCategory == "Все")
            {
                ViewBag.Products = products;
                if (category.PriceAscending == true && category.Price == 0)
                {
                    ViewBag.Products = products.OrderBy(u => u.Price);
                }
                if (category.PriceAscending == true && category.Price > 0)
                {
                    ViewBag.Products = products.Where(p => p.Price <= category.Price)
                                       .OrderBy(u => u.Price);
                }
                else if (category.PriceAscending == false && category.Price > 0)
                {
                    ViewBag.Products = products.Where(p => p.Price <= category.Price);
                }

                return(View(category));
            }

            ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory);
            if (category.PriceAscending == true && category.Price == 0)
            {
                ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory)
                                   .OrderBy(u => u.Price);
            }
            if (category.PriceAscending == true && category.Price > 0)
            {
                ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory)
                                   .Where(p => p.Price <= category.Price)
                                   .OrderBy(u => u.Price);
            }
            else if (category.PriceAscending == false && category.Price > 0)
            {
                ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory)
                                   .Where(p => p.Price <= category.Price);
            }


            return(View(category));
        }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: Alekseyya/ASP.net
        public ActionResult EditProduct(int?id)
        {
            if (id.HasValue)
            {
                EditProductViewModel product = null;
                using (var client = new service.ServiceClient())
                {
                    Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, EditProductViewModel>());
                    product = Mapper.Map <service.ProductDataContract, EditProductViewModel>(client.GetProduct((int)id));
                }
                return(View(product));
            }

            return(View(new EditProductViewModel()));
        }
コード例 #8
0
        public ActionResult Index()
        {
            var prodList = new List <service.Products>();

            using (var client = new service.ServiceClient())
            {
                foreach (var prod in client.GetListProducts())
                {
                    prodList.Add(new Products {
                        Id = prod.Id, Name = prod.Name, Count = prod.Count
                    });
                }
                ViewBag.Message = prodList;
            }
            return(View(prodList));
        }
コード例 #9
0
ファイル: CatalogLogic.cs プロジェクト: Alekseyya/ASP.net
        static public CategoryViewModel Ascending(string categoryName)
        {
            IEnumerable <IndexProductViewModel> products;

            using (var client = new service.ServiceClient())
            {
                Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, IndexProductViewModel>());
                products = Mapper.Map <IEnumerable <service.ProductDataContract>, IEnumerable <IndexProductViewModel> >(client.GetProducts());
            }
            var productsTmp = products.Where(cat => cat.Category == categoryName).OrderBy(p => p.Price);

            //using (var client = new service.ServiceClient())
            //{
            //    Mapper.Initialize(o => o.CreateMap<IndexProductViewModel, CategoryViewModel>());
            //    products = Mapper.Map<IEnumerable<IndexProductViewModel>, IEnumerable<CategoryViewModel>>(client.GetProducts());
            //}

            return(null);
        }
コード例 #10
0
        public ActionResult Catalog()
        {
            ViewBag.ShowModal = false;
            if (CartHelper.Cart.ItemsCount > 0 && !ModalShowed)
            {
                ViewBag.ShowModal = true;
                ModalShowed       = true;
            }
            IEnumerable <IndexProductViewModel> products;

            using (var client = new service.ServiceClient())
            {
                Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, IndexProductViewModel>());
                products = Mapper.Map <IEnumerable <service.ProductDataContract>, IEnumerable <IndexProductViewModel> >(client.GetProducts());
            }
            ViewBag.UserInfo = new UserViewModel {
                IsAuthenticated = User.Identity.IsAuthenticated, UserName = User.Identity.Name
            };
            ViewBag.Products = products;
            ///CatalogLogic logic = new CatalogLogic(new CategoryViewModel { ListProduct = products }, products);
            return(View(new CategoryViewModel {
                ListProduct = products
            }));
        }
コード例 #11
0
        public ActionResult Catalog(CategoryViewModel category)
        {
            IEnumerable <IndexProductViewModel> products;

            using (var client = new service.ServiceClient())
            {
                Mapper.Initialize(o => o.CreateMap <service.ProductDataContract, IndexProductViewModel>());
                products = Mapper.Map <IEnumerable <service.ProductDataContract>, IEnumerable <IndexProductViewModel> >(client.GetProducts());
            }

            CatalogLogic logic = new CatalogLogic(category, products);
            IEnumerable <IndexProductViewModel> productList = logic.GetListProducts(); //допустим пришло ВСЕ

            var prodListConditionPrice = logic.PriceBoundary(productList);             //учитывает все условия по цене

            if (category.Filter.PriceAscending == true)
            {
                var prodList = logic.AscendingPrice(prodListConditionPrice); //учитываем переключалку цены(по возрастанию)
                return(View(new CategoryViewModel
                {
                    Id = category.Id,
                    NameCategory = category.NameCategory,
                    Filter = new FilterModel
                    {
                        PriceAscending = true,
                        ByName = false,
                        PriceTo = category.Filter.PriceTo,
                        PriceFrom = category.Filter.PriceFrom
                    },
                    ListProduct = prodList.AsEnumerable()
                }));
            }
            else if (category.Filter.ByName == true)
            {
                var prodListByName = logic.ByName(prodListConditionPrice);
                return(View(new CategoryViewModel
                {
                    Id = category.Id,
                    NameCategory = category.NameCategory,
                    Filter = new FilterModel
                    {
                        PriceAscending = false,
                        ByName = true,
                        PriceTo = category.Filter.PriceTo,
                        PriceFrom = category.Filter.PriceFrom
                    },
                    ListProduct = prodListByName.AsEnumerable()
                }));
            }
            //var prodList = logic.AscendingPrice(prodListConditionPrice); //учитываем переключалку цены(по возрастанию)
            //var prodListByName = logic.ByName(prodList);
            return(View(new CategoryViewModel {
                ListProduct = prodListConditionPrice.AsEnumerable()
            }));


            #region Правильный вариант
            //if (category.NameCategory == "Все")
            //{
            //    ViewBag.Products = products;
            //    if (category.PriceAscending == true && category.PriceTo==0)
            //        ViewBag.Products = products.OrderBy(u => u.Price);
            //    if(category.PriceAscending == true && category.PriceTo > 0)
            //    {
            //        ViewBag.Products = products.Where(p => p.Price <= category.PriceTo)
            //                                   .OrderBy(u => u.Price);
            //    }else if (category.PriceAscending == false && category.PriceTo > 0)
            //    {
            //        ViewBag.Products = products.Where(p => p.Price <= category.PriceTo);
            //    }
            //    //Цены
            //    if (category.PriceTo == 0 && category.PriceFrom != 0)
            //    {
            //        ViewBag.Products = products.Where(p => p.Price >= category.PriceFrom)
            //                                       .OrderBy(u => u.Price);
            //    }
            //    else if (category.PriceTo != 0 && category.PriceFrom != 0)
            //    {
            //        ViewBag.Products = products.Where(p => p.Price >= category.PriceTo && p.Price <= category.PriceFrom)
            //                                       .OrderBy(u => u.Price);
            //    }

            //    return View(category);
            //}

            //ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory);
            //if (category.PriceAscending == true && category.PriceTo == 0)
            //    ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory)
            //                               .OrderBy(u => u.Price);
            //if (category.PriceAscending == true && category.PriceTo > 0)
            //{
            //    ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory)
            //                               .Where(p => p.Price <= category.PriceTo)
            //                               .OrderBy(u => u.Price);
            //}
            //else if (category.PriceAscending == false && category.PriceTo > 0)
            //{
            //    ViewBag.Products = products.ToList().FindAll(cat => cat.Category == category.NameCategory)
            //                               .Where(p => p.Price <= category.PriceTo);
            //}

            ////Категории до и после
            //if(category.PriceTo == 0 && category.PriceFrom!=0)
            //{
            //    ViewBag.Products = products.Where(p => p.Price >= category.PriceFrom && p.Category == category.NameCategory)
            //                                   .OrderBy(u => u.Price);
            //} else if (category.PriceTo !=0 && category.PriceFrom != 0)
            //{
            //    ViewBag.Products = products.Where(p => p.Price >= category.PriceTo && p.Price <= category.PriceFrom
            //                                                                         && p.Category == category.NameCategory)
            //                                   .OrderBy(u => u.Price);
            //}
            #endregion
        }