public IActionResult ProductFilter(string categoryCode) { ProductFilterViewModel productViewModel = new ProductFilterViewModel(); List <Product> products = _productBusinessService.GetAllWithBrandByCategoryCode(categoryCode); List <Categories> categories = _categoriesBusinessService.GetAllWithSubCategories(); //linq lambda productViewModel.Categories = categories.Select(x => new CategoryModel { Id = x.Id, Description = x.Description, Image = x.Image, Name = x.Name, Code = x.Code, SubCategories = x.SubCategories.Select(y => new SubCategoryModel { Description = y.Description, Name = y.Name, Code = y.Code, CategoryCode = y.Category.Code }).ToList() }).ToList(); productViewModel.Brands = (from p in products group p by p.BrandModel.Brand into b select new BrandQuantityModel { BrandId = b.Key.Id, BrandName = b.Key.Name, BrandQuantity = b.Count() }).OrderBy(x => x.BrandName).ToList(); return(View(productViewModel)); }
public IActionResult Index(ProductFilterViewModel filterModel) { var model = _productModelFactory.PrepareProductmodel(filterModel); //var xx = RenderPartialViewToString("_ProductList", model); return(View(model)); }
public async Task <IActionResult> Filter() { ProductInfoDto productInfo = null; try { productInfo = await _ProductFacade.GetCategoriesAndBrands(); } catch (HttpRequestException) { _logger.LogWarning("Exception Occured using Product Facade"); productInfo = null; } var viewModel = new ProductFilterViewModel() { /*Categories = productInfo.Categories, * Brands = productInfo.Brands,*/ }; ViewData["BrandId"] = new SelectList(productInfo.Brands, "BrandId", "Brand"); ViewData["CategoryId"] = new SelectList(productInfo.Categories, "CategoryId", "Category"); return(View(viewModel)); }
public IActionResult FilterSKUProperty(ProductFilterViewModel model) { // Creates a view model that consists of the entered price range // and a list of products ProductFilterViewModel filteredModel = new ProductFilterViewModel { PriceFrom = model.PriceFrom, PriceTo = model.PriceTo, FilteredProducts = LoadProducts(GetPriceWhereCondition(model)) }; return(View(filteredModel)); }
//EndDocSection:PagePropertyModel //DocSection:PagePropertyWhere /// <summary> /// Returns a where condition to correctly retrieve which products are selected in the filter. /// </summary> /// <param name="model">Model specifying all filtered products.</param> /// <returns>Where condition specifying which products are selected.</returns> private WhereCondition GetWithFeatureWhereCondition(ProductFilterViewModel model) { // Initializes a new where condition WhereCondition withFeatureWhere = new WhereCondition(); // If the feature is selected, sets the where condition if (model.LPTWithFeature) { withFeatureWhere.WhereTrue("LPTWithFeature"); } // Returns the where condition return(withFeatureWhere); }
//EndDocSection:SKUPropertyModel //DocSection:SKUPropertyWhere /// <summary> /// Returns a where condition to correctly retrieve which products are selected in the filter. /// </summary> /// <param name="model">Model specifying all filtered products.</param> /// <returns>Where condition specifying which products are selected.</returns> private WhereCondition GetPriceWhereCondition(ProductFilterViewModel model) { // Initializes a new where condition WhereCondition priceWhere = new WhereCondition(); // Sets the price where condition based on the model's values and limited by the price from-to range if (Constraint(model.PriceFrom, model.PriceTo)) { priceWhere.WhereGreaterOrEquals("SKUPrice", model.PriceFrom) .And().WhereLessOrEquals("SKUPrice", model.PriceTo); } // Returns the where condition return(priceWhere); }
public IActionResult Filter(ProductFilterViewModel filter) { var data = _productService.GetAllPaging(filter.CategoryId, filter.Keyword, filter.CurrentPage, filter.PageSize); var listContent = _viewRenderService.RenderToStringAsync("Product/_ListProduct", data.Results); var pagination = _viewRenderService.RenderToStringAsync("Common/_CommonPagination", data); return(Json(new JsonResponse() { Success = true, StatusCode = Utilities.Constants.StatusCode.GetDataSuccess, Message = Constants.GetDataSuccess, Data = listContent.Result, Pagination = pagination.Result })); }
//partial view for side filter, product is not mandatory, if given selected value heighlights public PartialViewResult ProductFilter(Product product) { ProductFilterViewModel model = new ProductFilterViewModel(); if (product != null) { model.SelectedProduct = product; } model.subCategories = context.Collection().Select(p => p.SubCategory).Distinct(); model.manufactures = context.Collection().Select(p => p.Manufacture).Distinct(); List <Product> products = context.Include(p => p.Images) .ToList(); model.products = products; return(PartialView(model)); }
// GET: Products public async Task <IActionResult> Index(string ProductGener, string searchString, int pageid = 1) { //ViewData["CategoryViewId"] = id; int skip = (pageid - 1) * 8; //var filterQuery = from m in _context.Product.Include(p => p.Category) orderby m.Category select m.Category; //var genreQuery = _context.Product.Include(k => k.Category).Select(kp => kp.Category.Name); var genreQuery = _context.Category.Select(p => p.Name); //var filterQuery = new SelectList(_context.Category, "Id", "Name"); var products = await _context.Product.Include(j => j.Category).ToListAsync(); //var applicationDbContext = _context.Product.Include(p => p.Category); if (!String.IsNullOrEmpty(searchString)) { products = products.Where(s => s.Name.Contains(searchString)).ToList(); } if (!String.IsNullOrEmpty(ProductGener)) { products = products.Where(x => x.Category.Name == ProductGener).ToList(); } int Count = products.Count(); ViewBag.PageID = pageid; ViewBag.searchString = searchString; //با ویومدل هم می شود ارسال نمود ViewBag.ProductGener = ProductGener; ViewBag.PageCount = Count / 8; var list = products.OrderBy(p => p.Id).Skip(skip).Take(8).ToList(); var productFilterViewModelVM = new ProductFilterViewModel(); productFilterViewModelVM.geners = new SelectList(await genreQuery.ToListAsync()); //ViewBag.Name = filterQuery; //productFilterViewModelVM.products = new SelectList(await filterQuery.Distinct().ToListAsync()); productFilterViewModelVM.products = list; return(View(productFilterViewModelVM)); }
public IActionResult ExportExcel(ProductFilterViewModel filter) { string sWebRootFolder = _hostingEnvironment.WebRootPath; string directory = Path.Combine(sWebRootFolder, "export-files"); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string sFileName = $"Product_{DateTime.Now:yyyyMMddhhmmss}.xlsx"; string fileUrl = $"{Request.Scheme}://{Request.Host}/export-files/{sFileName}"; FileInfo file = new FileInfo(Path.Combine(directory, sFileName)); if (file.Exists) { file.Delete(); file = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); } // var products = _productService.GetAll(); var products = _productService.GetAllPaging(filter.CategoryId, filter.Keyword, filter.CurrentPage, filter.PageSize); using (ExcelPackage package = new ExcelPackage(file)) { // add a new worksheet to the empty workbook ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Products"); worksheet.Cells["A1"].LoadFromCollection(products.Results, true, TableStyles.Light1); worksheet.Cells.AutoFitColumns(); package.Save(); //Save the workbook. } return(Json(new JsonResponse { Success = true, Message = Constants.GetDataSuccess, StatusCode = Utilities.Constants.StatusCode.GetDataSuccess, Data = fileUrl })); }