public async Task <ActionResult> Browse(int id, string name) { var categories = await _store.GetCategoriesByIdAsync(id); if (name == null && !Request.IsAjaxRequest()) { var products = await _store.GetProductsByShop(id); var categoryProductVM = new CategoryProductViewModel { categories = categories, products = products }; //return View(categoryProductVM); return(View(categoryProductVM)); } else { var products = await _store.GetProductsForAsync(name); var categoryProductVM = new CategoryProductViewModel { categories = categories, products = products }; return(PartialView("_Products", categoryProductVM)); } }
public ActionResult Index() { Random x = new Random(); var Products = _productRepository.GetAll().Where(item => !item.IsDeleted && item.Amount > 0).ToList(); List <Product> products = new List <Product>(); for (int i = 0; i < 4; i++) { if (Products.Count != 0) { var y = x.Next(0, Products.Count); products.Add(Products[y]); Products.RemoveAt(y); } } var result = new CategoryProductViewModel { Categories = _categoryRepository.FindBy(item => item.MasterCategoryId == null).ToList(), Products = products }; return(View(result)); }
// GET: Home/Delete/5 public PartialViewResult Category() { CategoryProductViewModel cat = new CategoryProductViewModel(); cat.cr = datas.categories.ToList(); //Soru !!Linq ile nasıl yaparım tekrarsız sutuna göre List <product> prs = datas.products.ToList(); for (int i = 0; i < prs.Count; i++) { if (i == 0) { cat.pr.Add(prs[i]); //int a=datas.products.Where(u => u.marka == prs[i].marka).GroupBy(u=>u.marka).Count(); } else if (prs[i - 1].marka != prs[i].marka) { cat.pr.Add(prs[i]); //cat.adet.Add(datas.products.Where(u => u.Id == prs[i].Id).Count()); } } return(PartialView(cat)); }
public IHttpActionResult GetStoreProducts(short Store_id, int Page = 0, int Items = 10) { try { CategoryProductViewModel responsee = new CategoryProductViewModel(); using (DunkeyContext ctx = new DunkeyContext()) { var res = ctx.Products .Where(x => x.Store_Id == Store_id && x.IsDeleted == false).OrderBy(x => x.Name).Skip(Page * Items).Take(Items).ToList(); var f = Mapper.Map <List <productslist> >(res); responsee.productslist = f; responsee.TotalRecords = ctx.Products.Where(x => x.Store_Id == Store_id && x.IsDeleted == false).Count(); CustomResponse <CategoryProductViewModel> response = new CustomResponse <CategoryProductViewModel> { Message = "Success", StatusCode = (int)HttpStatusCode.OK, Result = responsee }; return(Ok(response)); } } catch (Exception ex) { return(StatusCode(DunkeyDelivery.Utility.LogError(ex))); } }
public ActionResult Index() { TempData["NewProducts"] = MainDb.Products.Select(x => new ProductListViewModel() { ProductID = x.ProductID, ProductName = x.Name, CategoryID = x.CategoryID, SubCategoryID = x.SubCategoryID, UnitPrice = x.UnitPrice, AltText = x.AltText, ImageUrl = x.ImageUrl }).OrderBy(r => Guid.NewGuid()).Take(4).ToList(); CategoryProductViewModel[] p = new CategoryProductViewModel[categories.Count]; int i = 0; foreach (var category in categories) { var pList = MainDb.Products.Where(x => x.CategoryID == category.CategoryID).Select(x => new ProductListViewModel() { ProductID = x.ProductID, ProductName = x.Name, CategoryID = x.CategoryID, SubCategoryID = x.SubCategoryID, UnitPrice = x.UnitPrice, AltText = x.AltText, ImageUrl = x.ImageUrl }).OrderByDescending(r => r.ProductID).Take(6).ToList(); p.SetValue(new CategoryProductViewModel() { Category = category, Products = pList }, i); i++; } TempData["CategoryBadgeProducts"] = p; // kategorilerin resmini alıcak sonra ürünlerinden [AddBadge] true olanlardan son 4 tane seçicem return(View()); }
public IHttpActionResult GetAlcoholStores(string search_string, string CategoryType, int Store_Id) { try { CategoryProductViewModel res = new CategoryProductViewModel(); DunkeyContext ctx = new DunkeyContext(); if (string.IsNullOrEmpty(search_string)) { var productList = ctx.Products.Where(x => x.Store_Id == Store_Id && x.IsDeleted == false).ToList(); res.productslist = Mapper.Map <List <productslist> >(productList); //res.TotalRecords = ctx.Products.Where(x => x.Store.BusinessType == CategoryType).Count(); } else { var productList = ctx.Products.Where(x => x.Name.Contains(search_string) && x.Store_Id == Store_Id && x.IsDeleted == false).ToList(); res.productslist = Mapper.Map <List <productslist> >(productList); } CustomResponse <CategoryProductViewModel> response = new CustomResponse <CategoryProductViewModel> { Message = "Success", StatusCode = (int)HttpStatusCode.OK, Result = res }; return(Ok(response)); } catch (Exception ex) { return(StatusCode(DunkeyDelivery.Utility.LogError(ex))); } }
public ActionResult Search(decimal?PriceMin, decimal?PriceMax, string Category = "", string SearchString = "") { var _products = _productRepository.GetAll(); var result = new CategoryProductViewModel { Categories = _categoryRepository.FindBy(item => item.MasterCategoryId == null).ToList(), }; if (!String.IsNullOrEmpty(Category)) { List <string> MainCategoryWithSubCategories = new List <string>(); Category cat = _categoryRepository.FindBy(item => item.Id == Category).First(); GetAllCategories(cat, ref MainCategoryWithSubCategories); ViewBag.SelectedCategory = Category; _products = _products.Where(p => MainCategoryWithSubCategories.Contains(p.CategoryId)); } if (!String.IsNullOrEmpty(SearchString)) { ViewBag.SearchString = SearchString; _products = _products.Where(p => p.Name.Contains(SearchString)); } if (PriceMin != null) { ViewBag.PriceMin = PriceMin; _products = _products.Where(p => p.Price > PriceMin); } if (PriceMax != null) { ViewBag.PriceMax = PriceMax; _products = _products.Where(p => p.Price < PriceMax); } result.Products = _products.ToList(); return(View(result)); }
public CategoryProductViewModel Get(string id = "0") { CategoryProductViewModel categoryViewModel = new CategoryProductViewModel(); categoryViewModel.SubCategories = GetSubCategoriesByCategoryID(id); categoryViewModel.Products = GetProductsByCategoryID(id); categoryViewModel.Category = GetCategoryByCategoryID(id); return(categoryViewModel); }
public ActionResult ProductByCategory(int id) { CategoryProductViewModel cpvm = new CategoryProductViewModel(); Session["CategoryID"] = id; cpvm.product = _productService.GetAll(); cpvm.category = _categoryService.GetAll(); return(PartialView("_productPartial", cpvm)); }
public ActionResult ProductSearch(string Name, int page = 1, int pageSize = 4) { CategoryProductViewModel a = new CategoryProductViewModel(); a.product = _productService.GetElementByName(Name); a.category = _categoryService.GetAll(); PagedList <Product> model = new PagedList <Product>(a.product, page, pageSize); a.productList = model; return(PartialView("_productSearch", a)); }
[HandleError(ExceptionType = typeof(Exception), View = "Error")]//to handle all the exceptions we need to add this public ActionResult Index() { var model = new CategoryProductViewModel { Categories = categoryRepository.GetAll().ToList(), Products = productDB.Products.ToList(), SelectedCategoryId = 0, SelectedCategoryName = string.Empty }; return(View(model)); }
public async Task <ActionResult> ProductsPerCategory(int categoryID) { Category category = await _categoryRepository.GetByIDAsync(categoryID); List <CategoryProductViewModel> cpvm = new List <CategoryProductViewModel>(); foreach (var p in category.Products) { CategoryProductViewModel pvm = new CategoryProductViewModel(p); cpvm.Add(pvm); } return(Json(cpvm, JsonRequestBehavior.AllowGet)); }
public ActionResult CategoryProducts(string CategoryName) { CategoryProductViewModel viewModel = new CategoryProductViewModel(); CategoryProductDTO categoryProductsDTO = new CategoryProductDTO(); try { categoryProductsDTO = productBusinessContext.GetCategoryProducts(CategoryName); viewModel = CategoryMapper.Map <CategoryProductDTO, CategoryProductViewModel>(categoryProductsDTO); return(View(viewModel)); } catch (Exception ex) { return(View("Internal Error")); } }
public ActionResult Index(FormCollection collection) { var id = Convert.ToInt32("0" + collection["SelectedCategoryId"]); var products = productDb.Products.ToList(); var categories = categoryRepository.GetAll(); var selectedCategory = categories.FirstOrDefault(c => c.CategoryId == id); var matchingProducts = products.Where(c => c.CategoryId == selectedCategory.CategoryId); var model = new CategoryProductViewModel { Categories = categories.ToList(), Products = matchingProducts.ToList(), SelectedCategoryId = selectedCategory.CategoryId, SelectedCategoryName = selectedCategory.CategoryName }; return(View(model)); }
public async Task <ActionResult> ProductsNotInCategory(int categoryID) { Category category = await _categoryRepository.GetByIDAsync(categoryID); List <Product> productsInCategory = category.Products; List <Product> allProducts = await _productRepository.GetAllAsync(); List <Product> productsNotInCategory = allProducts.Where(p => p.Categories == null || (p.Categories.ToList().Find(c => c.CategoryID == categoryID)) == null).ToList(); List <CategoryProductViewModel> cpvm = new List <CategoryProductViewModel>(); foreach (var p in productsNotInCategory) { CategoryProductViewModel pvm = new CategoryProductViewModel(p); cpvm.Add(pvm); } return(Json(cpvm, JsonRequestBehavior.AllowGet)); }
//tüm ürünler ve kategorilerin listesi. public ActionResult ProductShow(int page = 1, int pageSize = 4) { //Session["language"] = Session["language"] != null ? Session["language"] : ""; if (Session["language"] != null) { Session["language"] = Session["language"]; } else { Session["language"] = ""; } PagedList <Product> model = new PagedList <Product>(_productService.GetAll(), page, pageSize); CategoryProductViewModel cpvm = new CategoryProductViewModel(); cpvm.productList = model; cpvm.category = _categoryService.GetAll(); return(View(cpvm)); }
// GET: Home public ActionResult Index(int?id) { if (user != null) { ViewBag.kullanici = "kullanici"; ViewBag.sepet = datas.baskets.Where(u => u.uid == user.Id && u.odeme == 2).Count(); } CategoryProductViewModel proc = new CategoryProductViewModel(); if (id == null) { proc.img = datas.images.ToList(); proc.pbr = datas.baskets.OrderByDescending(u => u.id).Take(3).ToList(); foreach (var item in proc.pbr) { foreach (var item2 in datas.images.ToList()) { if (item2.pid == item.pid) { proc.img2.Add(item2); } } } return(View(proc)); } proc.img = datas.images.Where(u => u.product.category.Id == id).ToList(); proc.pbr = datas.baskets.Take(5).ToList(); foreach (var item in proc.pbr) { foreach (var item2 in datas.images.ToList()) { if (item2.pid == item.pid) { proc.img2.Add(item2); } } } return(View(proc)); }
/// <summary> /// serach products from serach string /// </summary> /// <param name="SearchString">string for which user wants to search product</param> /// <returns></returns> public ActionResult SearchProducts(string SearchString) { var ProductViewConfig = new MapperConfiguration(cfg => { cfg.CreateMap <ProductViewModel, ProductDTO>(); cfg.CreateMap <VariantViewModel, VariantDTO>(); cfg.CreateMap <VariantImageViewModel, VariantImageDTO>(); }); IMapper ProductViewMapper = new Mapper(ProductViewConfig); CategoryProductBusiness categoryProductBusiness = new CategoryProductBusiness(); CategoryProductViewModel data = new CategoryProductViewModel(); try { CategoryProductDTO products = categoryProductBusiness.SearchProducts(SearchString); data = ProductViewMapper.Map <CategoryProductDTO, CategoryProductViewModel>(products); } catch (CategoryNotFoundException) { return(RedirectToAction("ErrorViewShow", "HttpErrors", new { msg = "product not found on this catgory" })); } return(View(data)); }
public IHttpActionResult GetCategoryProducts(short Category_Id, int Page = 0, int Items = 20) { try { CategoryProductViewModel responsee = new CategoryProductViewModel(); using (DunkeyContext ctx = new DunkeyContext()) { var res = ctx.Products .Where(x => x.Category_Id == Category_Id && x.IsDeleted == false).OrderBy(x => x.Image).Skip(Page * Items).Take(Items).ToList(); var f = Mapper.Map <List <productslist> >(res); responsee.productslist = f; foreach (var item in responsee.productslist) { var store = ctx.Stores.FirstOrDefault(x => x.Id == item.Store_id); item.BusinessName = store.BusinessName; item.BusinessType = store.BusinessType; item.MinDeliveryCharges = store.MinDeliveryCharges; item.MinDeliveryTime = store.MinDeliveryTime; item.MinOrderPrice = store.MinOrderPrice; } responsee.TotalRecords = ctx.Products.Where(x => x.Category_Id == Category_Id).Count(); CustomResponse <CategoryProductViewModel> response = new CustomResponse <CategoryProductViewModel> { Message = "Success", StatusCode = (int)HttpStatusCode.OK, Result = responsee }; return(Ok(response)); } } catch (Exception ex) { return(StatusCode(DunkeyDelivery.Utility.LogError(ex))); } }
/// <summary> /// get all product by the CategoryName /// </summary> /// <param name="CategoryName"></param> /// <returns></returns> public ActionResult GetProductByCat(string CategoryName) { /*mapping settings for getting the product by the category*/ var ProductViewConfig = new MapperConfiguration(cfg => { cfg.CreateMap <ProductViewModel, ProductDTO>(); cfg.CreateMap <VariantViewModel, VariantDTO>(); cfg.CreateMap <VariantImageViewModel, VariantImageDTO>(); }); IMapper ProductViewMapper = new Mapper(ProductViewConfig); CategoryProductBusiness categoryProductBusiness = new CategoryProductBusiness(); CategoryProductViewModel data = new CategoryProductViewModel(); try { CategoryProductDTO products = categoryProductBusiness.GetProductFromCatgory(CategoryName); data = ProductViewMapper.Map <CategoryProductDTO, CategoryProductViewModel>(products); } catch (CategoryNotFoundException) { return(RedirectToAction("ErrorViewShow", "HttpErrors", new { msg = "Product not found in this category" })); } return(View(data)); }
public async Task <ActionResult <CategoryProductViewModel> > Update([FromRoute] Guid id, [FromBody] CategoryProductViewModel viewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } if (id != viewModel.Id) { return(NotFound()); } var categoryProduct = await _categoryProductService.Update(_mapper.Map <CategoryProduct>(viewModel)); var resp = _mapper.Map <CategoryProductViewModel>(categoryProduct); return(CustomResponse(resp)); }