protected void btnExecute_Click(object sender, EventArgs e) { //Define a workbook to store null initially Workbook workbook = null; string path = MapPath("."); path = path.Substring(0, path.LastIndexOf("\\")); ProductsByCategory productsByCategory = new ProductsByCategory(path); //Create workbook based on a custom method of a class workbook = productsByCategory.CreateProductsByCategory(); if (ddlFileVersion.SelectedItem.Value == "XLS") { ////Save file and send to client browser using selected format workbook.Save(HttpContext.Current.Response, "ProductsByCategory.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003)); } else { workbook.Save(HttpContext.Current.Response, "ProductsByCategory.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx)); } //end response to avoid unneeded html HttpContext.Current.Response.End(); }
private static void AppendFilterOptionsToModel(ProductsByCategory model, IQueryable <Product> query) { model.FilterOption.Brands = query .Where(x => x.BrandId != null) .GroupBy(x => x.Brand) .Select(g => new FilterBrand { Id = (int)g.Key.Id, Name = g.Key.Name, SeoTitle = g.Key.SeoTitle, Count = g.Count() }).ToList(); }
private static void AppendFilterOptionsToModel(ProductsByCategory model, IQueryable <Product> query) { model.FilterOption.Price.MaxPrice = query.Max(x => x.Price); model.FilterOption.Price.MinPrice = query.Min(x => x.Price); model.FilterOption.Brands = query.Include(x => x.Brand) .Where(x => x.BrandId != null).ToList() .GroupBy(x => x.Brand) .Select(g => new FilterBrand { Id = g.Key.Id, Name = g.Key.Name, Slug = g.Key.Slug, Count = g.Count() }).ToList(); }
private void AppendFilterOptionsToModel(ProductsByCategory model, IQueryable <Product> query) { model.FilterOption.Price.MaxPrice = query.Max(x => x.Price); model.FilterOption.Price.MinPrice = query.Min(x => x.Price); var getCategoryName = _contentLocalizationService.GetLocalizationFunction <Category>(); model.FilterOption.Categories = query .SelectMany(x => x.Categories) .GroupBy(x => new { x.Category.Id, x.Category.Name, x.Category.Slug, x.Category.ParentId }) .Select(g => new FilterCategory { Id = (int)g.Key.Id, Name = g.Key.Name, Slug = g.Key.Slug, ParentId = g.Key.ParentId, Count = g.Count() }).ToList(); foreach (var item in model.FilterOption.Categories) { item.Name = getCategoryName(item.Id, nameof(item.Name), item.Name); } model.FilterOption.Brands = query.Include(x => x.Brand) .Where(x => x.BrandId != null).ToList() .GroupBy(x => x.Brand) .Select(g => new FilterBrand { Id = g.Key.Id, Name = g.Key.Name, Slug = g.Key.Slug, Count = g.Count() }).ToList(); }
private async void GetFoodItems(int categoryID) { CollectionsList = await _itemlistapi.GetListofItems(); var ProductItemsByCategory = new ObservableCollection <Product>(); var items = CollectionsList.Where(p => p.categories[0].id == categoryID).ToList(); foreach (var item in items) { ProductItemsByCategory.Add(item); } ProductsByCategory.Clear(); foreach (var item in ProductItemsByCategory) { ProductsByCategory.Add(item); } TotalProduuctItems = ProductsByCategory.Count; }
public void UpdateProductsByCategory( Category category, int before, int after) { using var db = GetDb(); int.TryParse(category.Id, out var id); var entity = db.ProductsByCategories.FirstOrDefault(p => p.CategoryId == id); if (entity == null) { entity = new ProductsByCategory { CategoryId = id, CategoryName = category.NameH1 }; db.ProductsByCategories.Add(entity); } entity.ProductsBeforeLinking = before; entity.ProductsAfterLinking = after; entity.UpdateDate = DateTime.Now; db.SaveChanges(); }
public IActionResult CategoryDetail(long id, SearchOption searchOption) { var category = _categoryRepository.Query().FirstOrDefault(x => x.Id == id); if (category == null) { return(Redirect("~/Error/FindNotFound")); } var model = new ProductsByCategory { CategoryId = category.Id, ParentCategorId = category.ParentId, CategoryName = category.Name, CategorySlug = category.Slug, CategoryMetaTitle = category.MetaTitle, CategoryMetaKeywords = category.MetaKeywords, CategoryMetaDescription = category.MetaDescription, CurrentSearchOption = searchOption, FilterOption = new FilterOption() }; var query = _productRepository .Query() .Where(x => x.Categories.Any(c => c.CategoryId == category.Id) && x.IsPublished && x.IsVisibleIndividually); if (query.Count() == 0) { model.TotalProduct = 0; return(View(model)); } AppendFilterOptionsToModel(model, query); if (searchOption.MinPrice.HasValue) { query = query.Where(x => x.Price >= searchOption.MinPrice.Value); } if (searchOption.MaxPrice.HasValue) { query = query.Where(x => x.Price <= searchOption.MaxPrice.Value); } var brands = searchOption.GetBrands(); if (brands.Any()) { var brandIs = _brandRepository.Query().Where(x => brands.Contains(x.Slug)).Select(x => x.Id).ToList(); query = query.Where(x => x.BrandId.HasValue && brandIs.Contains(x.BrandId.Value)); } model.TotalProduct = query.Count(); var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page; var offset = (_pageSize * currentPageNum) - _pageSize; while (currentPageNum > 1 && offset >= model.TotalProduct) { currentPageNum--; offset = (_pageSize * currentPageNum) - _pageSize; } query = query .Include(x => x.Brand) .Include(x => x.ThumbnailImage); query = AppySort(searchOption, query); var products = query .Select(x => ProductThumbnail.FromProduct(x)) .Skip(offset) .Take(_pageSize) .ToList(); foreach (var product in products) { product.ThumbnailUrl = _mediaService.GetThumbnailUrl(product.ThumbnailImage); product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product); } model.Products = products; model.CurrentSearchOption.PageSize = _pageSize; model.CurrentSearchOption.Page = currentPageNum; return(View(model)); }
public IActionResult CategoryDetail(long id, SearchOption searchOption) { var category = _categoryRepository.Query().FirstOrDefault(x => x.Id == id); if (category == null) { return(Redirect("~/Error/FindNotFound")); } var model = new ProductsByCategory { CategoryId = category.Id, ParentCategorId = category.ParentId, CategoryName = category.Name, CategorySeoTitle = category.SeoTitle, CurrentSearchOption = searchOption, FilterOption = new FilterOption() }; var query = _productRepository .Query() .Where(x => x.Categories.Any(c => c.CategoryId == category.Id) && x.IsPublished && x.IsVisibleIndividually); model.FilterOption.Price.MaxPrice = query.Max(x => x.Price); model.FilterOption.Price.MinPrice = query.Min(x => x.Price); if (searchOption.MinPrice.HasValue) { query = query.Where(x => x.Price >= searchOption.MinPrice.Value); } if (searchOption.MaxPrice.HasValue) { query = query.Where(x => x.Price <= searchOption.MaxPrice.Value); } AppendFilterOptionsToModel(model, query); var brands = searchOption.GetBrands(); if (brands.Any()) { var brandIs = _brandRepository.Query().Where(x => brands.Contains(x.SeoTitle)).Select(x => x.Id).ToList(); query = query.Where(x => x.BrandId.HasValue && brandIs.Contains(x.BrandId.Value)); } model.TotalProduct = query.Count(); var currentPageNum = searchOption.Page <= 0 ? 1 : searchOption.Page; var offset = (PageSize * currentPageNum) - PageSize; while (currentPageNum > 1 && offset >= model.TotalProduct) { currentPageNum--; offset = (PageSize * currentPageNum) - PageSize; } query = query .Include(x => x.Brand) .Include(x => x.ThumbnailImage); query = AppySort(searchOption, query); var products = query .Select(x => new ProductThumbnail { Id = x.Id, Name = x.Name, SeoTitle = x.SeoTitle, Price = x.Price, OldPrice = x.OldPrice, ThumbnailImage = x.ThumbnailImage, NumberVariation = x.ProductLinks.Count, ReviewsCount = x.ReviewsCount, RatingAverage = x.RatingAverage }) .Skip(offset) .Take(PageSize) .ToList(); foreach (var product in products) { product.ThumbnailUrl = _mediaService.GetThumbnailUrl(product.ThumbnailImage); } model.Products = products; model.CurrentSearchOption.PageSize = PageSize; model.CurrentSearchOption.Page = currentPageNum; return(View(model)); }
public ActionResult Index(string id) { Service service = new Service(); List <Category> categories = service.GetCategory(); ViewBag.Categories = categories; if (Session["sessionUser"] == "") { return(RedirectToAction("LoginPage", "UserLogin")); } var param = id ?? "2"; TempData["sub_id"] = id; int num; try { num = Int32.Parse(param); } catch (FormatException) { num = 2; } if (Request.IsAjaxRequest()) { ProductsByCategory products_category = new ProductsByCategory(num); List <Product> returning_List = products_category.ByCategory(); return(Json(returning_List, JsonRequestBehavior.AllowGet)); } if (num == 2) { //FAN subCategory filtering values. MarketplaceWebPortalApp.Models.FanFilter fanFilter = new Models.FanFilter(); var initialFanFilter = service.InitializeFanFilter(2010, 2020); fanFilter.minHeight = initialFanFilter.minHeight; fanFilter.maxHeight = initialFanFilter.maxHeight; fanFilter.minVoltage = initialFanFilter.minVoltage; fanFilter.maxVoltage = initialFanFilter.maxVoltage; fanFilter.minPower = initialFanFilter.minPower; fanFilter.maxPower = initialFanFilter.maxPower; fanFilter.minSpeed = initialFanFilter.minSpeed; fanFilter.maxSpeed = initialFanFilter.maxSpeed; string json = new JavaScriptSerializer().Serialize(fanFilter); ViewData["jsonStr"] = json; ViewData["Fields"] = "['Operating Voltage (VAC) (Min & Max)','Power(W) (Min & Max)','Fan Speed(RPM) (Min & Max)','Height(in) (Min & Max)']"; } else if (num == 4) { //TABLET subCategory filtering values. MarketplaceWebPortalApp.Models.TabletFilter tabletFilter = new Models.TabletFilter(); var initialTabletFilter = service.InitializeTabletFilter(2010, 2020); tabletFilter.minRAM = initialTabletFilter.minRAM; tabletFilter.maxRAM = initialTabletFilter.maxRAM; tabletFilter.minScreen = initialTabletFilter.minScreen; tabletFilter.maxScreen = initialTabletFilter.maxScreen; tabletFilter.minStorage = initialTabletFilter.minStorage; tabletFilter.maxStorage = initialTabletFilter.maxStorage; string json = new JavaScriptSerializer().Serialize(tabletFilter); ViewData["jsonStr"] = json; ViewData["Fields"] = "['Screen Size(in)','Storage(GB)','RAM(GB)']"; } else if (num == 10) { //SOFA subCategory filtering values. MarketplaceWebPortalApp.Models.SofaFilter sofaFilter = new Models.SofaFilter(); var initialSofaFilter = service.InitializeSofaFilter(2010, 2021); sofaFilter.minLength = initialSofaFilter.minLength; sofaFilter.maxLength = initialSofaFilter.maxLength; string json = new JavaScriptSerializer().Serialize(sofaFilter); ViewData["jsonStr"] = json; ViewData["Fields"] = "['Length(in)']"; } TempData["sub_id_from_search"] = id; return(View()); }
public IActionResult ProductsByCategory(string catSeoTitle, SearchOption searchOption) { var category = categoryRepository.Query().FirstOrDefault(x => x.SeoTitle == catSeoTitle); if (category == null) { return(Redirect("~/Error/FindNotFound")); } var model = new ProductsByCategory { CategoryId = category.Id, ParentCategorId = category.ParentId, CategoryName = category.Name, CategorySeoTitle = category.SeoTitle, CurrentSearchOption = searchOption, FilterOption = new FilterOption() }; var query = productCategoryRepository .Query() .Where(x => x.CategoryId == category.Id && x.Product.IsPublished) .Select(x => x.Product); model.FilterOption.Price.MaxPrice = query.Max(x => x.Price); model.FilterOption.Price.MinPrice = query.Min(x => x.Price); if (searchOption.MinPrice.HasValue) { query = query.Where(x => x.Price >= searchOption.MinPrice.Value); } if (searchOption.MaxPrice.HasValue) { query = query.Where(x => x.Price <= searchOption.MaxPrice.Value); } AppendFilterOptionsToModel(model, query); var brands = searchOption.GetBrands(); if (brands.Any()) { var brandIs = brandRepository.Query().Where(x => brands.Contains(x.SeoTitle)).Select(x => x.Id).ToList(); query = query.Where(x => x.BrandId.HasValue && brandIs.Contains(x.BrandId.Value)); } model.TotalProduct = query.Count(); query = query .Include(x => x.Brand) .Include(x => x.ThumbnailImage) .Include(x => x.Variations); query = AppySort(searchOption, query); var products = query .Select(x => new ProductListItem { Id = x.Id, Name = x.Name, SeoTitle = x.SeoTitle, Price = x.Price, OldPrice = x.OldPrice, ThumbnailImage = x.ThumbnailImage }).ToList(); foreach (var product in products) { product.ThumbnailUrl = mediaService.GetThumbnailUrl(product.ThumbnailImage); } model.Products = products; return(View(model)); }