Example #1
0
        public async Task <IActionResult> Index(int cat = 0, string title = null)
        {
            ViewBag.Category = ((List <NoticesCategoryModel>)(await _categoryrepo.GetAll()).Data).Where(x => x.NC_IsDeleted == false && x.NC_Status && x.NC_Type == 1).OrderBy(x => x.NC_SortField).ToList();

            var ProdCatList = (List <ProductCategoryModel>)(await _categories.GetAll()).Data;

            ProdCatList.Where(x => x.PC_ParentId == 0 && x.PC_Status && x.PC_IsDeleted != true).ToList();
            ViewBag.ProductCategory = ProdCatList;
            var AllNews = ((List <NoticesModel>)(await _noticesrepo.GetAll()).Data).Where(x => x.N_IsDeleted == false && x.N_Status && x.N_Type == 1).OrderBy(x => x.N_Sort).ToList();

            return(View(AllNews));
        }
        public async Task <IActionResult> Index()
        {
            try
            {
                ViewBag.category = null;
                List <ProductModel> items = new List <ProductModel>();
                string cookie             = "";
                HttpContext.Request.Cookies.TryGetValue("Compaire", out cookie);
                var ProdCatList = (List <ProductCategoryModel>)(await _categories.GetAll()).Data;
                ViewBag.ProductCategory = ProdCatList.Where(x => x.PC_ParentId == 0 && x.PC_Status).ToList();

                if (cookie != null)
                {
                    var decryptCookie      = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie);
                    CompareCookieModel ccm = JsonConvert.DeserializeObject <CompareCookieModel>(decryptCookie);


                    foreach (var item in ccm.Products)
                    {
                        var p = await _productrepo.GetById(item);

                        items.Add(p);
                    }
                }
                if (items.Count() > 0)
                {
                    var getAllProductByCatId = ((List <ProductModel>)(await _productrepo.GetAll()).Data).Where(x => x.P_EndLevelCatId == items.FirstOrDefault().P_EndLevelCatId).ToList();
                    foreach (var item in items)
                    {
                        getAllProductByCatId.Remove(item);
                    }
                    ViewBag.getAllProductByCatId = getAllProductByCatId;
                    #region Brand
                    var BrandGroups = getAllProductByCatId.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
                }
                else
                {
                    ViewBag.Brands = ((List <BrandModel>)(await _brandrepo.GetAll()).Data).Where(x => x.B_Status).ToList();
                }
                return(View(items));
            }
            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));
            }
        }
Example #4
0
        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"));
            }
        }
Example #5
0
        public async Task <IActionResult> Result(
            string q,
            string TitleSerch,
            int?order        = null,
            bool isAvilable  = false,
            bool fast        = false,
            bool isajax      = false,
            int[] Brand      = null,
            int Catid        = 0,
            int page         = 1,
            decimal minPrice = 0,
            decimal maxprice = 0

            )
        {
            var AllProduct = ((List <ProductModel>)(await _productrepo.GetAll()).Data).ToList();

            string[] QueryStrings = q.Split(" ");
            if (QueryStrings.Count() > 0)
            {
                AllProduct = AllProduct.Where(x => x.P_Status && QueryStrings.Any(y => x.P_Title.Contains(y, StringComparison.InvariantCultureIgnoreCase) || x.P_Description.Contains(y, StringComparison.InvariantCultureIgnoreCase) || (x.P_BrandTitle != null && x.P_BrandTitle.Contains(y, StringComparison.InvariantCultureIgnoreCase)))).Take(8).ToList();
            }


            if (Catid > 0)
            {
                AllProduct = AllProduct.Where(x => x.P_MainCatId == Catid || x.P_EndLevelCatId == Catid).ToList();
            }
            ViewBag.Minprice = 0;
            ViewBag.MaxPrice = 0;
            ViewBag.id       = q;
            ViewBag.catid    = Catid;
            #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.DefaultProductCombine != null).Min(x => x.DefaultProductCombine.PriceModel.Price);
                ViewBag.MaxPrice = AllProduct.Where(x => x.DefaultProductCombine != null).Max(x => x.DefaultProductCombine.PriceModel.Price);
            }
            #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 (!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 (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;
            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));
        }