public IActionResult Index() { CatalogueViewModel vm = new CatalogueViewModel(); // only build the catalogue once if (HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands) == null) { try { BrandModel brandModel = new BrandModel(_db); // now load the Brands List <Brand> Brands = brandModel.GetAll(); HttpContext.Session.SetObject(SessionVars.Brands, Brands); vm.SetBrands(HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands)); } catch (Exception ex) { ViewBag.Message = "Catalogue Problem - " + ex.Message; } } else { vm.SetBrands(HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands)); } GetAllProducts(); return(View(vm)); }
public CatalogueView() { InitializeComponent(); BindingContext = (ViewModel = new CatalogueViewModel()); Favorites.Clicked += Favorite_Clicked; ToolbarItems.Add(Favorites); catalogueView = this; }
public IActionResult Index(int categoryId) { CatalogueViewModel catalogueViewModel = new CatalogueViewModel(); catalogueViewModel.Category = _categoryRepository.GetCategoryByID(categoryId); catalogueViewModel.Products = _productRepository.GetProductsByCategoryId(categoryId); return(View("Index", catalogueViewModel)); }
public IActionResult Index(int subcategoryId, int categoryId) { CatalogueViewModel catalogueViewModel = new CatalogueViewModel(); catalogueViewModel.Category = _categoryRepository.GetCategoryByID(categoryId); int categoryDetailId = _categoryRepository.GetSubCategoryForCategoryByID(categoryId, subcategoryId).CategoryDetailId; catalogueViewModel.Products = _productRepository.GetProductsByCategoryDetailId(categoryDetailId); return(View("Index", catalogueViewModel)); }
public ActionResult SelectItem(CatalogueViewModel vm) { Dictionary <string, object> ShoppingCart; if (HttpContext.Session.GetObject <Dictionary <string, Object> >(SessionVars.ShoppingCart) == null) { ShoppingCart = new Dictionary <string, object>(); } else { ShoppingCart = HttpContext.Session.GetObject <Dictionary <string, object> >(SessionVars.ShoppingCart); } ProductViewModel[] catalogue = HttpContext.Session.GetObject <ProductViewModel[]>(SessionVars.Catalogue); String retMsg = ""; foreach (ProductViewModel item in catalogue) { if (item.Id == vm.Id) { if (vm.Qty > 0) // update only selected item { item.Qty = vm.Qty; retMsg = vm.Qty + " - item(s) Added!"; ShoppingCart[item.Id] = item; } else { item.Qty = 0; ShoppingCart.Remove(item.Id); retMsg = "item(s) Removed!"; } vm.BrandId = item.BrandId; break; } } ViewBag.AddMessage = retMsg; HttpContext.Session.SetObject(SessionVars.ShoppingCart, ShoppingCart); vm.SetBrands(HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands)); return(View("Index", vm)); }
public IActionResult SelectBrand(CatalogueViewModel vm) { BrandModel brandModel = new BrandModel(_db); ProductModel productModel = new ProductModel(_db); List <Product> items = productModel.GetAllByBrand(vm.BrandId); List <ProductViewModel> vms = new List <ProductViewModel>(); if (items.Count > 0) { foreach (Product item in items) { ProductViewModel mvm = new ProductViewModel(); mvm.Qty = 0; mvm.BrandId = item.BrandId; mvm.BrandName = brandModel.GetName(item.BrandId); mvm.ProductName = item.ProductName; mvm.Description = item.Description; mvm.GraphicName = item.GraphicName; mvm.CostPrice = item.CostPrice; mvm.MSRP = item.MSRP; mvm.QtyOnHand = item.QtyOnHand; mvm.QtyOnBackOrder = item.QtyOnBackOrder; mvm.Id = item.Id; mvm.HP = item.HP; mvm.ATTACK = item.Attack; mvm.DEFENCE = item.Defence; mvm.SPECIALATTACK = item.SpecialAttack; mvm.SPECIALDEFENCE = item.SpecialDefence; mvm.SPEED = item.Speed; vms.Add(mvm); } ProductViewModel[] myCat = vms.ToArray(); HttpContext.Session.SetObject(SessionVars.Catalogue, myCat); } vm.SetBrands(HttpContext.Session.GetObject <List <Brand> >(SessionVars.Brands)); return(View("Index", vm)); }
/// <summary> /// Pulls genres and developers from database for filtering /// </summary> /// <returns> /// Returns a list of genres and developers from database /// </returns> public ActionResult Catalogue() { var Model = new CatalogueViewModel() { applications = db.Applications.Where(x => x.approved == true).OrderByDescending(x => x.genre).ToList(), genres = new List <string>(), developers = new List <string>() }; foreach (var app in Model.applications) { if (!Model.genres.Contains(app.genre)) { Model.genres.Add(app.genre); } if (!Model.developers.Contains(app.developer)) { Model.developers.Add(app.developer); } } return(View(Model)); }
public ActionResult FilterCatalogue(string genre, string developer, int rating) { var Model = new CatalogueViewModel(); Model.applications = db.Applications.Where(x => x.approved == true).ToList(); Model.genres = new List <string>(); Model.developers = new List <string>(); foreach (var app in Model.applications) { if (!Model.genres.Contains(app.genre)) { Model.genres.Add(app.genre); } if (!Model.developers.Contains(app.developer)) { Model.developers.Add(app.developer); } } //Filter the results by the provided filters if (genre != "Any") { Model.applications = Model.applications.Where(x => x.genre == genre).ToList(); } if (developer != "Any") { Model.applications = Model.applications.Where(x => x.developer == developer).ToList(); } if (rating != 0) { Model.applications = Model.applications.Where(x => x.rating >= rating).ToList(); } return(View("~/Views/Home/Catalogue.cshtml", Model)); }
private CatalogueViewModel GetCatalogueViewModel(ref IEnumerable <PPProduit> listeProduits, string Vendeur, string Categorie, string Page, string Size, string Filtre, Tri tri) { int noPage = int.TryParse(Page, out noPage) ? noPage : 1; int nbItemsParPage = int.TryParse(Size, out nbItemsParPage) ? nbItemsParPage : DEFAULTITEMPARPAGE; //chercher la categorie PPCategory categorie; int NoCategorie; if (string.IsNullOrEmpty(Categorie) || !int.TryParse(Categorie, out NoCategorie)) { categorie = null; } else { var requeteCategorie = from uneCategorie in context.PPCategories where uneCategorie.NoCategorie == NoCategorie select uneCategorie; categorie = requeteCategorie.FirstOrDefault(); } //chercher le vendeur PPVendeur vendeur; int NoVendeur; if (Vendeur == "-1" || string.IsNullOrEmpty(Vendeur) || !int.TryParse(Vendeur, out NoVendeur)) { vendeur = new PPVendeur { NoVendeur = -1 }; //creer la liste de produits listeProduits = (from p in context.PPProduits.Where(p => p.Disponibilité == true) select p) .Where(p => categorie == null || p.PPCategory == categorie); } else { var requete = from unVendeur in context.PPVendeurs where unVendeur.NoVendeur == NoVendeur select unVendeur; vendeur = requete.FirstOrDefault(); CreateVisiteVendeur((int)vendeur.NoVendeur); //creer la liste de produits listeProduits = vendeur.PPProduits.Where(p => p.Disponibilité == true) .Where(p => (categorie == null || p.PPCategory == categorie) && p.Disponibilité == true); } if (!string.IsNullOrEmpty(Filtre)) { listeProduits = listeProduits.Where(p => p.Nom.ToLower().Contains(Filtre.ToLower())); } switch (tri) { case Tri.Nom: listeProduits = listeProduits.OrderBy(p => p.Nom); break; case Tri.Categorie: listeProduits = listeProduits.OrderBy(p => p.PPCategory.Description); break; case Tri.Date: listeProduits = listeProduits.OrderBy(p => p.DateCreation); break; case Tri.Numero: listeProduits = listeProduits.OrderBy(p => p.NoProduit); break; default: listeProduits = listeProduits.OrderBy(p => p.Nom); break; } //creer le view model var viewModel = new CatalogueViewModel { Vendeur = vendeur, Vendeurs = (from unVendeur in context.PPVendeurs select unVendeur).ToList(), Categories = (from uneCategorie in context.PPCategories select uneCategorie).ToList(), Categorie = categorie, Produits = listeProduits.Skip(noPage * (nbItemsParPage == -1 ? listeProduits.Count() : nbItemsParPage) - (nbItemsParPage == -1 ? listeProduits.Count() : nbItemsParPage)) .Take(nbItemsParPage == -1 ? listeProduits.Count() : nbItemsParPage).ToList() }; return(viewModel); }
public ActionResult BoilerList( CatalogueViewModel model, string firm, string category, string linkName, int page = 1, bool isAjax = false, string filter = "default") { ViewBag.Category = category; ViewBag.Firm = firm; ViewBag.IsAjax = isAjax; ViewBag.Filter = filter; ViewBag.LinkName = linkName; var products = productRepo.Products.ToList(); model.Categories = products.Select(n => n.Category).ToList().Distinct(); if (category != null) { model.Firms = products .Where(f => f.Category == category) .Select(n => n.Firm).ToList().Distinct(); } else { model.Firms = products.Select(n => n.Firm).ToList().Distinct(); } // тут получаем характеристики текущей категории var categories = categoryRepo.Categories.ToList(); model.CategoryFeatures = new List <string>(); if (categories.Any() && !string.IsNullOrEmpty(category)) { var categoryId = categories .Where(c => c.Name == category) .Select(c => c.Id) .Single(); var catFeatureIds = categoryFeatureRepo.CategoryFeatures .Where(cf => cf.CategoryId == categoryId) .Select(cf => cf.FeatureId) .ToList(); model.CategoryFeatures = catFeatureIds.Join(productFeatureRepo.ProductFeatures, p => p, t => t.Id, (p, t) => t.Name).ToList(); } // feature ranges // получить минимальные и максимальные цены model.FeatureRanges = new List <FeatureRange>(); model.FeatureRanges.Add( new FeatureRange { FeatureName = "Цена", From = products.Min(p => p.Price), To = products.Max(p => p.Price) } ); // filter by category and firm products = FilterProductList(products, category, firm); var prodFeatures = productFeatureRepo.ProductFeatures.ToList(); var productWithFeaturesList = new List <ProductWithFeatures>(); if (products.Any()) { foreach (var item in products) { var prodWithFeatures = new ProductWithFeatures { Product = item, ProductFeatures = prodFeatures.Where(f => f.ProductId == item.ProductID).ToList() }; productWithFeaturesList.Add(prodWithFeatures); } productWithFeaturesList = OrderProductWithFeaturesList(productWithFeaturesList, linkName, filter); model.ProductList = new ProductListViewModel { ProductWithFeaturesList = productWithFeaturesList .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = productWithFeaturesList.Count() } }; return(PartialView("BoilerList", model)); } else { return(PartialView("ErrorPage", "Список товаров не найден")); } }
private void InitializeData() { var sizeId = Guid.NewGuid(); var sizeName = "Medium"; var sizeCode = "M"; var size = new Size { Id = sizeId, Name = sizeName, Code = sizeCode }; var sizeVm = new SizeViewModel { Id = sizeId, Name = sizeName, Code = sizeCode }; var productVarId = Guid.NewGuid(); var productVarName = "Orange"; var productVarColor = "Orange"; var productVariant = new ProductVariant { Id = productVarId, Name = productVarName, Color = productVarColor, Size = size, SizeId = size.Id }; var productVariantVm = new ProductVariantViewModel { Id = productVarId, Name = productVarName, Color = productVarColor, Size = sizeVm }; var productId = Guid.NewGuid(); var prodName = "Blue Jeans"; var prodDimensions = "23x56x21"; var product = new Product { Id = productId, Name = prodName, Dimensions = prodDimensions, Variant = productVariant, VariantId = productVariant.Id }; var productViewModel = new ProductViewModel { Id = productId, Name = prodName, Dimensions = prodDimensions, Variant = productVariantVm }; var prodVarId1 = Guid.NewGuid(); var prodVarName1 = "Yellow"; var prodVarColor1 = "Yellow"; var productVariant1 = new ProductVariant { Id = prodVarId1, Name = prodVarName1, Color = prodVarColor1 }; var productVariantVm1 = new ProductVariantViewModel { Id = prodVarId1, Name = prodVarName1, Color = prodVarColor1 }; var prodId1 = Guid.NewGuid(); var prodName1 = "Blue Jeans"; var prodDimensions1 = "53x51x99"; var product1 = new Product { Id = prodId1, Name = prodName1, Dimensions = prodDimensions1, Variant = productVariant1, VariantId = productVariant1.Id }; var productVm1 = new ProductViewModel { Id = prodId1, Name = prodName1, Dimensions = prodDimensions1, Variant = productVariantVm1 }; var prodId2 = Guid.NewGuid(); var prodName2 = "Precious"; var prodDimensions2 = "13x36x61"; var product2 = new Product { Id = prodId2, Name = prodName2, Dimensions = prodDimensions2 }; var prodVm2 = new ProductViewModel { Id = prodId2, Name = prodName2, Dimensions = prodDimensions2 }; Context.Set <Size>().Add(size); Context.Set <ProductVariant>().Add(productVariant); Context.Set <Product>().Add(product); Context.Set <ProductVariant>().Add(productVariant1); Context.Set <Product>().Add(product1); Context.Set <Product>().Add(product2); var catId = Guid.NewGuid(); var catName = "Halloween"; var category = new Category { Id = catId, Name = catName, Products = new List <Product> { product, product2, product1 } }; var cat = new CategoryViewModel { Id = catId, Name = catName, Products = new List <ProductViewModel> { productViewModel, productVm1, prodVm2 } }; var catId1 = Guid.NewGuid(); var catName1 = "Test Drive"; var category1 = new Category { Id = catId1, Name = catName1, Products = new List <Product> { product2, product1 } }; var cat1 = new CategoryViewModel { Id = catId1, Name = catName1, Products = new List <ProductViewModel> { prodVm2, productVm1 } }; var catId2 = Guid.NewGuid(); var catName2 = "Empty products"; var category2 = new Category { Id = catId2, Name = catName2 }; var cat2 = new CategoryViewModel { Id = catId2, Name = catName2 }; Context.Set <Category>().Add(category); Context.Set <Category>().Add(category1); Context.Set <Category>().Add(category2); var catalId = Guid.NewGuid(); var catalName = "Catalogue # 1"; var catalogue = new Catalogue { Id = catalId, Name = catalName }; catalogue.Categories.AddRange(new[] { category, category1 }); var catalVm = new CatalogueViewModel { Id = catalId, Name = catalName, Categories = new[] { cat, cat1 } }; var catalId1 = Guid.NewGuid(); var catalName1 = "Catalogue # 2"; var catalogue1 = new Catalogue { Id = catalId1, Name = catalName1 }; catalogue1.Categories.AddRange(new[] { category, category1, category2 }); var catalVm1 = new CatalogueViewModel { Id = catalId1, Name = catalName1, Categories = new [] { cat, cat1, cat2 } }; Context.Set <Catalogue>().Add(catalogue); Context.Set <Catalogue>().Add(catalogue1); var catalGrId = Guid.NewGuid(); var catalGrName = "CatalogueGroup #1"; var catalogueGroup = new CatalogueGroup { Id = catalGrId, Name = catalGrName }; catalogueGroup.Catalogues.Add(catalogue); var catalGrVm = new CatalogueGroupViewModel { Id = catalGrId, Name = catalGrName, Catalogues = new List <CatalogueViewModel> { catalVm } }; var catalGrId1 = Guid.NewGuid(); var catalGrId2 = "CatalogueGroup #2"; var catalogueGroup1 = new CatalogueGroup { Id = catalGrId1, Name = catalGrId2 }; catalogueGroup1.Catalogues.AddRange(new[] { catalogue, catalogue1 }); var catalGrVm1 = new CatalogueGroupViewModel { Id = catalGrId1, Name = catalGrId2, Catalogues = new List <CatalogueViewModel> { catalVm, catalVm1 } }; _planResult = new List <CatalogueGroupViewModel> { catalGrVm, catalGrVm1 }; Context.Set <CatalogueGroup>().Add(catalogueGroup); Context.Set <CatalogueGroup>().Add(catalogueGroup1); Context.SaveChanges(); }
private void InitializeData() { var sizeId = Guid.NewGuid(); var sizeName = "Medium"; var sizeCode = "M"; var size = new Size { Id = sizeId, Name = sizeName, Code = sizeCode }; var sizeVm = new SizeViewModel { Id = sizeId, Name = sizeName, Code = sizeCode }; var productVarId = Guid.NewGuid(); var productVarName = "Orange"; var productVarColor = "Orange"; var productVariant = new ProductVariant { Id = productVarId, Name = productVarName, Color = productVarColor, Size = size, SizeId = size.Id }; var productVariantVm = new ProductVariantViewModel { Id = productVarId, Name = productVarName, Color = productVarColor, Size = sizeVm }; var productId = Guid.NewGuid(); var prodName = "Blue Jeans"; var prodDimensions = "23x56x21"; var product = new Product { Id = productId, Name = prodName, Dimensions = prodDimensions, Variant = productVariant, VariantId = productVariant.Id }; var productViewModel = new ProductViewModel { Id = productId, Name = prodName, Dimensions = prodDimensions, Variant = productVariantVm }; var prodVarId1 = Guid.NewGuid(); var prodVarName1 = "Yellow"; var prodVarColor1 = "Yellow"; var productVariant1 = new ProductVariant { Id = prodVarId1, Name = prodVarName1, Color = prodVarColor1 }; var productVariantVm1 = new ProductVariantViewModel { Id = prodVarId1, Name = prodVarName1, Color = prodVarColor1 }; var prodId1 = Guid.NewGuid(); var prodName1 = "Blue Jeans"; var prodDimensions1 = "53x51x99"; var product1 = new Product { Id = prodId1, Name = prodName1, Dimensions = prodDimensions1, Variant = productVariant1, VariantId = productVariant1.Id }; var productVm1 = new ProductViewModel { Id = prodId1, Name = prodName1, Dimensions = prodDimensions1, Variant = productVariantVm1 }; var prodId2 = Guid.NewGuid(); var prodName2 = "Precious"; var prodDimensions2 = "13x36x61"; var product2 = new Product { Id = prodId2, Name = prodName2, Dimensions = prodDimensions2 }; var prodVm2 = new ProductViewModel { Id = prodId2, Name = prodName2, Dimensions = prodDimensions2 }; Context.Set<Size>().Add(size); Context.Set<ProductVariant>().Add(productVariant); Context.Set<Product>().Add(product); Context.Set<ProductVariant>().Add(productVariant1); Context.Set<Product>().Add(product1); Context.Set<Product>().Add(product2); var catId = Guid.NewGuid(); var catName = "Halloween"; var category = new Category { Id = catId, Name = catName, Products = new List<Product> { product, product2, product1 } }; var cat = new CategoryViewModel { Id = catId, Name = catName, Products = new List<ProductViewModel> { productViewModel, productVm1, prodVm2 } }; var catId1 = Guid.NewGuid(); var catName1 = "Test Drive"; var category1 = new Category { Id = catId1, Name = catName1, Products = new List<Product> { product2, product1 } }; var cat1 = new CategoryViewModel { Id = catId1, Name = catName1, Products = new List<ProductViewModel> { prodVm2, productVm1 } }; var catId2 = Guid.NewGuid(); var catName2 = "Empty products"; var category2 = new Category { Id = catId2, Name = catName2 }; var cat2 = new CategoryViewModel { Id = catId2, Name = catName2 }; Context.Set<Category>().Add(category); Context.Set<Category>().Add(category1); Context.Set<Category>().Add(category2); var catalId = Guid.NewGuid(); var catalName = "Catalogue # 1"; var catalogue = new Catalogue { Id = catalId, Name = catalName }; catalogue.Categories.AddRange(new[] { category, category1 }); var catalVm = new CatalogueViewModel { Id = catalId, Name = catalName, Categories = new[] { cat, cat1 } }; var catalId1 = Guid.NewGuid(); var catalName1 = "Catalogue # 2"; var catalogue1 = new Catalogue { Id = catalId1, Name = catalName1 }; catalogue1.Categories.AddRange(new[] { category, category1, category2 }); var catalVm1 = new CatalogueViewModel { Id = catalId1, Name = catalName1, Categories = new [] { cat, cat1, cat2 } }; Context.Set<Catalogue>().Add(catalogue); Context.Set<Catalogue>().Add(catalogue1); var catalGrId = Guid.NewGuid(); var catalGrName = "CatalogueGroup #1"; var catalogueGroup = new CatalogueGroup { Id = catalGrId, Name = catalGrName }; catalogueGroup.Catalogues.Add(catalogue); var catalGrVm = new CatalogueGroupViewModel { Id = catalGrId, Name = catalGrName, Catalogues = new List<CatalogueViewModel> { catalVm } }; var catalGrId1 = Guid.NewGuid(); var catalGrId2 = "CatalogueGroup #2"; var catalogueGroup1 = new CatalogueGroup { Id = catalGrId1, Name = catalGrId2 }; catalogueGroup1.Catalogues.AddRange(new[] { catalogue, catalogue1 }); var catalGrVm1 = new CatalogueGroupViewModel { Id = catalGrId1, Name = catalGrId2, Catalogues = new List<CatalogueViewModel> { catalVm, catalVm1 } }; _planResult = new List<CatalogueGroupViewModel> { catalGrVm, catalGrVm1 }; Context.Set<CatalogueGroup>().Add(catalogueGroup); Context.Set<CatalogueGroup>().Add(catalogueGroup1); Context.SaveChanges(); }