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())); }
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)); }
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); } }
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")); }
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")); }
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)); }
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())); }
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)); }
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); }
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 })); }
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 }