public async Task <IActionResult> GetAllFestivals(int fest) { try { var AllFests = ((List <FestivalOfferModel>)(await _festivalrepo.GetAll()).Data).Where(x => x.F_IsDeleted == false).ToList(); List <object> Result = new List <object>(); foreach (var item in AllFests) { if (item.F_Type == 1) ///is for all products { Result.Add(new { Id = item.F_Id, Type = item.F_Type, Title = item.F_Title, Discount = item.F_Discount, TypeStr = "همه محصولات", Status = item.F_Status, }); } else { var cat = await _productcatrepo.GetById(item.F_EndLevelCategoryId); if (cat != null) { Result.Add(new { Id = item.F_Id, Type = item.F_Type, Title = item.F_Title, Discount = item.F_Discount, TypeStr = cat.PC_Title, Status = item.F_Status, CategoryId = cat.PC_Id, CategoryTitle = cat.PC_Title }); } } } return(new JsonResult(ResponseModel.Success(data: Result))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
public async Task <IActionResult> Index( string TitleSerch, int?order = null, bool isAvilable = false, bool fast = false, bool isajax = false, int[] Brand = null, int[] attribute = null, int cat1 = 0, int cat2 = 0, int page = 1, decimal minPrice = 0, decimal maxprice = 0 ) { try { var refUrl = Request.Headers["Referer"].ToString(); var ProdCatList = (List <ProductCategoryModel>)(await _categories.GetAll()).Data; if (refUrl.Contains("offer") || refUrl.Contains("Offer")) { ViewBag.FilterOffered = true; } else { ViewBag.FilterOffered = false; } ViewBag.ProductCategory = ProdCatList.Where(x => x.PC_ParentId == cat1 && x.PC_Status && !x.PC_IsDeleted).ToList(); var Catlvl1 = await _categories.GetById(cat1); if (Catlvl1 != null) { ViewBag.CatTitle = Catlvl1.PC_Title; ViewBag.description = Catlvl1.PC_Description; ViewBag.CatSeo = Catlvl1.PC_Seo; ViewBag.CatL1 = Catlvl1; } else { ViewBag.CatL1 = null; } if (cat2 > 0) { var Catlvl2 = await _categories.GetById(cat2); if (Catlvl2 != null) { ViewBag.description = Catlvl2.PC_Description; ViewBag.CatSeo = Catlvl2.PC_Seo; ViewBag.CatL2 = Catlvl2; } else { ViewBag.CatL2 = null; } } else { ViewBag.CatL2 = null; } var seo = Barayand.Common.Services.UtilesService.ParseSeoData(Catlvl1.PC_Seo); ViewBag.CatId = cat1; ViewBag.CatId2 = cat2; ViewBag.pagetype = 1; ViewBag.CatUrl1 = seo.url.ToString(); var AllProduct = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_Status && x.P_MainCatId == cat1).OrderBy(x => x.P_Sort).OrderBy(x => x.P_LabelIds.Count() > 0) /*.OrderBy(x=>x.P_Labels.FirstOrDefault(l=>l.L_Title.Equals("جدید")))*/.ToList(); if (cat2 > 0) { AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == cat2).ToList(); } ViewBag.Minprice = 0; ViewBag.MaxPrice = 10; #region GetPrice if (AllProduct.Where(x => x.IsAvailable).Count() > 0) { ViewBag.Minprice = AllProduct.Where(x => x.DefaultProductCombine != null).Min(x => x.DefaultProductCombine.PriceModel.Price); ViewBag.MaxPrice = AllProduct.Where(x => x.DefaultProductCombine != null).Max(x => x.DefaultProductCombine.PriceModel.Price); } #endregion #region Attrbute if (!isajax) { List <AttributeAnswerList> Attributes = new List <AttributeAnswerList>(); List <CatAttrRelationModel> catAttrs = ((List <CatAttrRelationModel>)(await _catattrrepo.GetAll()).Data).Where(x => x.X_IsDeleted != true).ToList(); foreach (var catttr in catAttrs) { if (catttr.X_CatId == cat1 || catttr.X_CatId == cat2) { var attr = await _attrrepo.GetById(catttr.X_AttrId); if (attr != null && attr.A_Type == 1 && attr.A_UseInSearch && attr.A_Status && attr.A_IsDeleted == false) { List <AttrAnswerModel> answers = ((List <AttrAnswerModel>)(await _attransrepo.GetAll()).Data).Where(x => x.X_CatAttrId == catttr.X_Id && !x.X_IsDeleted && x.X_Status).ToList(); Attributes.Add(new AttributeAnswerList() { Attribute = attr, Answers = answers }); } } } ViewBag.Attributes = Attributes; } #endregion #region Brand var BrandGroups = AllProduct.GroupBy(x => x.P_BrandId)?.Select(x => x.FirstOrDefault().P_BrandId).ToList(); ViewBag.Brands = ((List <BrandModel>)(await _brandrepo.GetAll()).Data).Where(x => BrandGroups.Contains(x.B_Id)).ToList(); #endregion #region Filter if (cat2 != 0) { AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == cat2).ToList(); } if (!string.IsNullOrEmpty(order.ToString())) { switch (order) { case 1: //See AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList(); break; case 2: //sell AllProduct = AllProduct.OrderByDescending(x => x.P_SaleCount).ToList(); break; case 3: //fav AllProduct = AllProduct.OrderByDescending(x => x.ManualRate).ToList(); break; case 4: //new AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList(); break; case 5: //cheap AllProduct = AllProduct.Where(x => x.DefaultProductCombine != null && x.DefaultProductCombine.PriceModel != null).OrderBy(x => (x.DefaultProductCombine.PriceModel.Price)).ToList(); break; case 6: //expenc AllProduct = AllProduct.Where(x => x.DefaultProductCombine != null && x.DefaultProductCombine.PriceModel != null).OrderByDescending(x => x.DefaultProductCombine.PriceModel.Price).ToList(); break; case 7: //fast AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList(); break; case 8: //bestoffer AllProduct = AllProduct.Where(x => x.P_BestOffer).ToList(); break; default: break; } } if (!string.IsNullOrEmpty(TitleSerch)) { AllProduct = AllProduct.Where(x => x.P_Title.Contains(TitleSerch, StringComparison.InvariantCultureIgnoreCase)).ToList(); } if (Brand != null && Brand.Count() > 0) { AllProduct = AllProduct.Where(x => Brand.Contains(x.P_BrandId)).ToList(); } if (attribute != null && attribute.Count() > 0) { List <int> AllFilteredProdsByAnsId = new List <int>(); foreach (int aid in attribute) { var r = await _prodansRepo.GetProductsByAnswer(aid); AllFilteredProdsByAnsId.AddRange(r); } AllProduct = AllProduct.Where(x => AllFilteredProdsByAnsId.Contains(x.P_Id)).ToList(); } if (fast) { AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList(); } if (isAvilable) { AllProduct = AllProduct.Where(x => x.IsAvailable).ToList(); } if (minPrice > 0 && maxprice > 0) { AllProduct = AllProduct.Where(x => x.DefaultProductCombine.PriceModel.Price >= minPrice && x.DefaultProductCombine.PriceModel.Price <= maxprice).ToList(); } #endregion #region Paging Paging paging = new Paging(); paging.TotalCount = AllProduct.Count(); paging.PageSize = 30; if ((int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize) < page) { page = 1; } paging.CurrentPage = page; paging.TotalPages = (int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize); ViewBag.paging = paging; #endregion if (ViewBag.Minprice == ViewBag.MaxPrice) { ViewBag.MaxPrice = ViewBag.MaxPrice + 100; } var items = AllProduct.Skip((paging.CurrentPage - 1) * paging.PageSize).Take(paging.PageSize).ToList(); if (isajax) { return(View("_ProductList", items)); } return(View(items)); } catch (Exception ex) { _logger.LogError("", ex); return(Content(ex.Message)); } }
public async Task <IActionResult> Brand( int id, bool isAjax, string TitleSerch, bool isAvilable = false, bool fast = false, int?order = null, decimal minPrice = 0, decimal maxprice = 0, int page = 1, int?catid = null ) { try { if (id != 0) { int?catlvlcheck = null; var AllProduct = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_Status && x.P_BrandId == id && !x.P_IsDeleted).ToList(); ViewBag.brand = await _brandrepo.GetById(id); ViewBag.catid = catid; ViewBag.openattr = null; if (catid != null) { var catbrand = await _categories.GetById(catid); catlvlcheck = (catbrand.PC_ParentId == 0) ? 1 : 2; if (catbrand.PC_ParentId == 0) { ViewBag.openattr = catid; } else { ViewBag.openattr = catbrand.PC_ParentId; } } #region Category var Catlvl2 = AllProduct.GroupBy(x => x.P_EndLevelCatId)?.Select(x => x.FirstOrDefault().P_EndLevelCatId).ToList(); var Catlvl1 = AllProduct.GroupBy(x => x.P_MainCatId)?.Select(x => x.FirstOrDefault().P_MainCatId).ToList(); ViewBag.Catlvl2 = ((List <ProductCategoryModel>)(await _categories.GetAll()).Data).Where(x => Catlvl2.Contains(x.PC_Id)).ToList(); ViewBag.Catlvl1 = ((List <ProductCategoryModel>)(await _categories.GetAll()).Data).Where(x => Catlvl1.Contains(x.PC_Id)).ToList(); #endregion #region GetPrice if (AllProduct.Where(x => x.IsAvailable).Count() > 0) { ViewBag.Minprice = AllProduct.Where(x => x.IsAvailable).Min(x => x.DefaultProductCombine.CalculatedPrice()); ViewBag.MaxPrice = AllProduct.Where(x => x.IsAvailable).Max(x => x.DefaultProductCombine.CalculatedPrice()); } if (ViewBag.Minprice == ViewBag.MaxPrice) { ViewBag.MaxPrice = ViewBag.MaxPrice + 100; } #endregion if (catlvlcheck != null) { if (catlvlcheck == 1) { AllProduct = AllProduct.Where(x => x.P_MainCatId == catid).ToList(); } else { AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == catid).ToList(); } } if (!string.IsNullOrEmpty(TitleSerch)) { AllProduct = AllProduct.Where(x => x.P_Title.Contains(TitleSerch, StringComparison.InvariantCultureIgnoreCase)).ToList(); } if (!string.IsNullOrEmpty(order.ToString())) { switch (order) { case 1: //See AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList(); break; case 2: //sell AllProduct = AllProduct.OrderByDescending(x => x.P_SaleCount).ToList(); break; case 3: //fav AllProduct = AllProduct.OrderByDescending(x => x.ManualRate).ToList(); break; case 4: //new AllProduct = AllProduct.OrderByDescending(x => x.VisitCount).ToList(); break; case 5: //cheap AllProduct = AllProduct.Where(x => x.Warranties.Count > 0).OrderBy(x => (x.DefaultProductCombine.CalculatedPrice())).ToList(); break; case 6: //expenc AllProduct = AllProduct.Where(x => x.Warranties.Count > 0).OrderByDescending(x => x.DefaultProductCombine.CalculatedPrice()).ToList(); break; case 7: //fast AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList(); break; case 8: //bestoffer AllProduct = AllProduct.Where(x => x.P_BestOffer).ToList(); break; default: break; } } if (fast) { AllProduct = AllProduct.Where(x => x.P_ImmediateSend).ToList(); } if (isAvilable) { AllProduct = AllProduct.Where(x => x.IsAvailable).ToList(); } if (minPrice > 0 && maxprice > 0) { AllProduct = AllProduct.Where(x => x.Warranties.Count > 0 && x.DefaultProductCombine.CalculatedPrice() >= minPrice && x.DefaultProductCombine.CalculatedPrice() <= maxprice).ToList(); } if (catid != null) { AllProduct = AllProduct.Where(x => x.P_EndLevelCatId == catid || x.P_MainCatId == catid).ToList(); } #region Paging Paging paging = new Paging(); paging.TotalCount = AllProduct.Count(); paging.PageSize = 30; paging.CurrentPage = page; paging.TotalPages = (int)Math.Ceiling(paging.TotalCount / (double)paging.PageSize); ViewBag.paging = paging; #endregion var items = AllProduct.Skip((paging.CurrentPage - 1) * paging.PageSize).Take(paging.PageSize).ToList(); if (isAjax) { return(View("_ProductList", items)); } return(View(items)); } return(RedirectToAction("Index", "Home")); } catch (Exception ex) { _logger.LogError("Brands", ex); return(RedirectToAction("Index", "Home")); } }