public IActionResult ViewCategory() { CathegoryManager cm = new CathegoryManager(_clientFactory, _contextAccessor); List <CathegoryResponse> categories = cm.Get(); return(View(categories)); }
public IActionResult RemoveSize(string id, string key) { ProductManager pm = new ProductManager(_clientFactory, _contextAccessor); ProductResponse product = pm.Get(id); List <ProductQuantity> size = product.Size; size.RemoveAll(x => x.Size == key); CathegoryManager cm = new CathegoryManager(_clientFactory, _contextAccessor); var cathegories = cm.Get(); //int categoryId = cathegories.Where(x => x.Products.Contains(product)).Select(x => x.Id).FirstOrDefault(); ProductRequest request = new ProductRequest { Name = product.Name, ProductSKU = product.ProductSKU, LongDescription = product.LongDescription, ShortDescription = product.ShortDescription, OriginalPrice = product.OriginalPrice, ActualPrice = product.ActualPrice, IsLive = product.IsLive, ImagePath = product.ImagePath, ThumbnailPath = product.ThumbnailPath, Size = size, CategoryId = product.CategoryId }; pm.Put(request); return(RedirectToAction("ViewSizes", "Admin", new { id = product.Id.ToString() })); }
public IActionResult ViewProduct() { ProductManager pm = new ProductManager(_clientFactory, _contextAccessor); List <ProductResponse> products = pm.Get(); CathegoryManager cm = new CathegoryManager(_clientFactory, _contextAccessor); List <CathegoryResponse> categories = cm.Get(); return(View(new ProductView(products, categories))); }
public IActionResult AddCategory(string name) { CathegoryManager cm = new CathegoryManager(_clientFactory, _contextAccessor); CathegoryRequest request = new CathegoryRequest() { Name = name }; cm.Post(request); return(RedirectToAction("ViewCategory", "Admin")); }
public IActionResult Index(int pageNum = 1, int pageSize = 4, int?category = null, string search = null) { List <int> ids = new List <int>(); // delete later CathegoryManager cm = new CathegoryManager(_clientFactory, _contextAccessor); var allCategories = cm.Get(); var selectedCategories = new List <CathegoryResponse>(); if (category != null && allCategories.Any(x => x.Id == category && x.Products.Count > 0)) { selectedCategories = allCategories.Where(x => x.Id == category).ToList(); } else if (category != null && (!selectedCategories.Any(x => x.Id == category) || (selectedCategories.Any(x => x.Products.Count == 0)))) { selectedCategories.Clear(); } else if (category == null) { selectedCategories = allCategories; } List <ProductResponse> allProducts = new List <ProductResponse>(); // Adds all products to a list foreach (var currentCategory in selectedCategories) { // product list needs to be separate from the category response for pagination if (currentCategory.Products != null && currentCategory.Products.Count > 0) { allProducts.AddRange(currentCategory.Products); } } if (search != null && search.Length > 2) { var foundProducts = allProducts.Where(x => x.Name.ToUpper().Contains(search.ToUpper())).ToList(); if (foundProducts.Count > 0) { allProducts = foundProducts; } else { allProducts.Clear(); } } // Example: 54 products, 10 per page // 54/10 = 5 // 54%10 = 4 -> 4 != 0 -> TotalPages++ int totalPages = allProducts.Count / pageSize; if (allProducts.Count % pageSize != 0) { totalPages++; } // Get the required products allProducts = allProducts.Skip((pageNum - 1) * pageSize).Take(pageSize).ToList(); return(View(new IndexView(allCategories, allProducts, pageNum, pageSize, category, totalPages, search))); }