コード例 #1
0
        //for deals
        public List <product7> allProducts(List <int> variantId, int DealId)
        {
            var all = db.ProductVariantDetails.Where(x => x.IsActive == true && x.Product.IsActive == true && x.Product.IsEnable == true)
                      .Include(x => x.Product.ProductImages)
                      .Include(x => x.Product.RatingReviews)
                      .ToList();
            var result = new List <ProductVariantDetail>();

            foreach (var id in variantId)
            {
                var data = all.Where(x => x.Id == id).Select(X => new ProductVariantDetail()
                {
                    Id                 = X.Id,
                    IsActive           = X.IsActive,
                    IsDefault          = X.IsDefault,
                    Product            = X.Product,
                    Weight             = X.Weight,
                    Discount           = X.Discount,
                    CostPrice          = X.CostPrice,
                    InStock            = X.InStock,
                    Price              = X.Price,
                    PriceAfterdiscount = X.PriceAfterdiscount,
                    ProductId          = X.ProductId,
                    ProductImages      = X.ProductImages.Where(x => x.IsActive == true).ToList(),
                    ProductSKU         = X.ProductSKU,
                }).FirstOrDefault();
                if (data != null)
                {
                    result.Add(data);
                }
            }


            result = DealHelper.calculateDealonetime(result, DealId, db);
            result = PriceIncrementHelper.calculatePrice(result, db);

            var list = new List <product7>();

            foreach (var r in result)
            {
                var model = new product7();
                model.InStock                           = r.InStock;
                model.CostPrice                         = r.CostPrice;
                model.Discount                          = r.Discount;
                model.Id                                = r.ProductId;
                model.SellingPrice                      = r.Price;
                model.VariantDetailId                   = r.Id;
                model.LandingVariant.InStock            = r.InStock;
                model.LandingVariant.Id                 = r.Id;
                model.LandingVariant.Price              = r.Price;
                model.LandingVariant.PriceAfterdiscount = r.PriceAfterdiscount;
                model.Name                              = r.Product?.Name;
                model.ShipmentVendor                    = r.Product?.ShipmentVendor ?? false;
                model.ShipmentTime                      = r.Product?.ShipmentTime ?? 0;
                model.ShipmentCost                      = r.Product?.ShipmentCost ?? 0;
                model.PriceAfterdiscount                = r.PriceAfterdiscount;
                model.ProductCategoryId                 = Convert.ToInt32(r.Product?.ProductCategoryId);
                if (r.Product?.ProductImages.Where(x => x.IsActive == true).Count() != 0)
                {
                    model.Url    = r.Product?.ProductImages?.Where(x => x.IsActive == true).FirstOrDefault().ImagePath;
                    model.Url150 = r.Product?.ProductImages?.Where(x => x.IsActive == true).FirstOrDefault().ImagePath150x150;
                    model.Url450 = r.Product?.ProductImages?.Where(x => x.IsActive == true).FirstOrDefault().ImagePath450x450;
                }
                var rating = all.Where(x => x.Id == r.Id).Select(x => x.Product.RatingReviews).FirstOrDefault();
                model.Rating      = rating.Select(x => x.Rating).FirstOrDefault();
                model.Description = r.Product?.Description;
                list.Add(model);
            }
            return(list);
        }
コード例 #2
0
        public List <ProductCatalogue> getFilterProducts([FromBody] Filter filter, [FromQuery] int page, [FromQuery] int pagesize)
        {
            try
            {
                if (filter.SearchData == "undefined" || filter.SearchData == null)
                {
                    filter.SearchData = "";
                }
                var model    = new List <ProductCatalogue>();
                var products = db.Products.Where(x => x.IsActive == true && x.IsEnable == true && x.ProductCategory.IsShow == true);
                var prodIds  = db.HomeCategoryProduct.Where(x => x.IsActive == true && x.HomeCategoryId == filter.CategoryId).Select(x => x.ProductId).ToList();
                var prod     = new List <Product>();

                decimal minprice = 0;
                decimal maxprice = 0;

                if (filter.SelectedVariants.Count() > 0)
                {
                    foreach (var s in filter.SelectedVariants)
                    {
                        var result = new List <Product>();
                        foreach (var o in s.VariantOptionId)
                        {
                            var pro = from cv in db.CategoryVariants
                                      where s.CategoryId == cv.ProductCategoryId && s.VariantId == cv.VariantId
                                      join pvo in db.ProductVariantOptions on cv.Id equals pvo.CategoryVariantId
                                      join pvd in db.ProductVariantDetails on pvo.ProductVariantDetailId equals pvd.Id
                                      join p in products on pvd.ProductId equals p.Id
                                      where o == pvo.VariantOptionId &&
                                      cv.IsActive == true && pvo.IsActive == true && pvd.IsActive == true && p.IsActive == true
                                      select p;
                            result.AddRange(pro.ToList());
                        }
                        products = result.AsQueryable();
                    }
                }
                var variantsData = new List <ProductVariantDetail>();
                foreach (var p in prodIds)
                {
                    if (products.Any(x => x.Id == p))
                    {
                        prod.Add(products.Where(x => x.Id == p).Include(x => x.ProductVariantDetails).FirstOrDefault());
                    }
                }
                foreach (var item in prod)
                {
                    if (item.ProductVariantDetails == null)
                    {
                        item.ProductVariantDetails = db.ProductVariantDetails.Where(x => x.ProductId == item.Id && x.IsActive == true).ToList();
                    }
                    var data = item.ProductVariantDetails.Where(b => b.IsActive == true).ToList();
                    variantsData.AddRange(data);
                }
                //variantsData.OrderByDescending(x => x.Id);
                var priceListdata = new List <ProductVariantDetail>();
                var plist         = prod.ToList();
                var variantlist   = db.ProductVariantDetails.Where(x => x.IsActive == true).Include(x => x.Product).ToList();
                foreach (var p in plist)
                {
                    var list = variantlist.Where(x => x.ProductId == p.Id).ToList();
                    priceListdata.AddRange(list);
                }
                //pricefilter
                var minprice1 = priceListdata.Count() == 0 ? 0 : priceListdata.Min(x => x.Price);
                var maxprice1 = priceListdata.Count() == 0 ? 0 : priceListdata.Max(x => x.Price);
                var pricelist = PriceRange(maxprice1, minprice1);

                var list1 = new List <ProductVariantDetail>();
                minprice = filter.MinPrice != "" && filter.MinPrice != "0" ? Convert.ToDecimal(filter.MinPrice.Split('$')[1]) : 0;
                maxprice = filter.MaxPrice != "" && filter.MaxPrice != "0" ? Convert.ToDecimal(filter.MaxPrice.Split('$')[1]) : 0;
                if (maxprice == 0)
                {
                    list1 = variantsData.Where(x => x.Price >= minprice).ToList();
                }
                else
                {
                    list1 = variantsData.Where(x => x.Price >= minprice && x.Price < maxprice).ToList();
                }
                //search by name
                //var data11 =
                foreach (var l in list1)
                {
                    if (l.Product == null)
                    {
                        l.Product = db.Products.Where(x => x.Id == l.ProductId && x.IsActive == true && x.IsEnable == true).FirstOrDefault();
                    }
                }

                //get data for page
                var final = list1.OrderByDescending(x => x.Id).Skip((page - 1) * pagesize).Take(pagesize).ToList();
                var count = list1.Count();

                var ProductVariantOptions = db.ProductVariantOptions.Where(b => b.IsActive == true).ToList();
                var optionsList           = db.VariantOptions.Where(b => b.IsActive == true).Include(x => x.Variant).ToList();

                var variantsList = new List <ProductVariantDetail>();
                final = DealHelper.calculateDeal(final, db);
                final = PriceIncrementHelper.calculatePrice(final, db);

                foreach (var p in final)
                {
                    var pro = new ProductCatalogue();
                    pro.Id = p.ProductId;
                    //pro.Name = p.Product.Name;
                    var pdata = prod.Where(x => x.Id == p.ProductId).FirstOrDefault();
                    pro.Name                = pdata?.Name;
                    pro.ShipmentVendor      = pdata?.ShipmentVendor ?? false;
                    pro.ShipmentCost        = pdata?.ShipmentCost ?? 0;
                    pro.ShipmentTime        = pdata?.ShipmentTime ?? 0;
                    pro.Description         = pdata?.Description;
                    pro.ProductCategoryName = pdata?.ProductCategory?.Name;
                    pro.ProductCategoryId   = Convert.ToInt32(pdata?.ProductCategoryId);

                    pro.InStock = p.InStock;

                    pro.VariantDetailId    = p.Id;
                    pro.Discount           = p.Discount;
                    pro.SellingPrice       = p.Price;
                    pro.PriceAfterDiscount = p.PriceAfterdiscount;
                    //}


                    var selectedImage = new ProductImage();
                    selectedImage = db.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true && x.ProductVariantDetailId == p.Id).FirstOrDefault();
                    if (selectedImage == null)
                    {
                        selectedImage = db.ProductImages.Where(x => x.IsActive == true && x.ProductVariantDetailId == pro.VariantDetailId).FirstOrDefault();
                    }
                    pro.Image    = selectedImage?.ImagePath;
                    pro.Image150 = selectedImage?.ImagePath150x150;
                    pro.Image450 = selectedImage?.ImagePath450x450;

                    var VariantOptionIds = ProductVariantOptions.Where(x => x.ProductVariantDetailId == pro.VariantDetailId && x.IsActive == true).ToList().Select(x => x.VariantOptionId);
                    foreach (var v in VariantOptionIds)
                    {
                        var data = optionsList.Where(x => x.Id == v && x.IsActive == true).FirstOrDefault().RemoveReferences();
                        pro.VariantOptions.Add(data);
                    }
                    pro.Rating    = db.RatingReviews.Where(x => x.IsActive == true && x.ReviewStatusId == 1 && x.ProductId == p.ProductId).FirstOrDefault()?.Rating;
                    pro.Count     = count;
                    pro.PriceList = pricelist;
                    pro.AvgRate   = AvgRating(p.Id);
                    pro.ActiveTo  = p.ActiveTo;
                    if (pdata != null)
                    {
                        model.Add(pro);
                    }
                }


                //rate
                model = model.Where(x => x.AvgRate >= filter.AvgRate).OrderByDescending(x => x.Id).ToList();
                //sorting
                if (filter.SortBy == "HighToLow")
                {
                    model = model.OrderByDescending(x => x.PriceAfterDiscount).ToList();
                }
                else if (filter.SortBy == "LowToHigh")
                {
                    model = model.OrderBy(x => x.PriceAfterDiscount).ToList();
                }
                if (model.Count == 0)
                {
                    var model1 = new ProductCatalogue();
                    model1.PriceList = pricelist;
                    model.Add(model1);
                }

                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
ファイル: HomePageController.cs プロジェクト: nat124/navApi
        public async Task <IActionResult> GetLikeProducts(string IpAddress, int UserId)


        {
            var list = new List <ProductTag>();

            if (UserId > 0)
            {
                var result = from log in db.UserLogs
                             where log.IsActive == true && log.UserId == UserId && log.Url.Contains("product-details")
                             join tags in db.ProductTag on log.ProductId equals tags.ProductId
                             join p in db.Products on tags.ProductId equals p.Id
                             select tags;
                list = await result.ToListAsync();
            }
            else
            {
                var result = from log in db.UserLogs
                             where log.IsActive == true && (log.UserId == null || log.UserId == 0) && log.IPAddress == IpAddress && log.Url.Contains("product-details")
                             join tags in db.ProductTag on log.ProductId equals tags.ProductId
                             join p in db.Products on tags.ProductId equals p.Id
                             select tags;
                list = result.ToList();
            }
            var ids = list.Select(x => x.ProductId).Distinct();

            list = new List <ProductTag>();
            foreach (var l in ids)
            {
                list.AddRange(db.ProductTag.Where(x => x.ProductId == l).ToList());
            }
            var alltags   = db.ProductTag.Where(x => x.IsActive == true).ToList();
            var finaltags = new List <ProductTag>();

            foreach (var l in list)
            {
                var get = alltags.Where(x => x.TagId == l.TagId && x.ProductId != l.ProductId).ToList();
                finaltags.AddRange(get);
            }
            var final = new List <ProductCatalogue>();

            foreach (var l in finaltags)
            {
                var one     = new ProductCatalogue();
                var variant = db.ProductVariantDetails.Where(x => x.IsActive == true && x.ProductId == l.ProductId).FirstOrDefault();
                var varlist = new List <ProductVariantDetail>();

                if (variant != null)
                {
                    varlist.Add(variant);

                    varlist                = DealHelper.calculateDeal(varlist, db);
                    varlist                = PriceIncrementHelper.calculatePrice(varlist, db);
                    variant                = varlist[0];
                    one.Id                 = l.ProductId;
                    one.Name               = db.Products.Where(x => x.Id == l.ProductId).FirstOrDefault().Name;
                    one.CostPrice          = variant.CostPrice;
                    one.Discount           = variant.Discount;
                    one.PriceAfterDiscount = variant.PriceAfterdiscount;
                    one.SellingPrice       = variant.Price;
                    var image = db.ProductImages.Where(x => x.IsActive == true && x.IsDefault == true && x.ProductVariantDetailId == variant.Id).Select(x => x.ImagePath150x150).FirstOrDefault();
                    one.Image150 = image == null?db.ProductImages.Where(x => x.IsActive == true && x.ProductVariantDetailId == variant.Id).Select(x => x.ImagePath150x150).FirstOrDefault() : image;

                    one.InStock         = variant.InStock;
                    one.VariantDetailId = variant.Id;
                    final.Add(one);
                }
            }
            return(Ok(final.Take(20).ToList()));
        }
コード例 #4
0
ファイル: CartController.cs プロジェクト: nat124/navApi
        public List <GetCart> GetCartByCustomerPromo(int CustomerId, string ip)
        {
            var carts   = new List <Cart>();
            var cart    = new Cart();
            var vendors = db.Users.Where(b => b.IsActive == true).ToList();

            if (CustomerId > 0)
            {
                carts = db.Carts.Where(x => x.UserId == CustomerId && x.IsActive == true && x.IsConvertToCheckout == false).Include(x => x.CartItems).ToList();
            }
            //else
            //{
            //    carts = db.Carts.Where(x => x.IpAddress == ip && x.IsActive == true && x.UserId == null && x.IsConvertToCheckout == false).Include(x => x.CartItems).ToList();
            //}
            //to add all cartitems in first cart
            if (carts.Count() > 1)
            {
                cart = carts[0];
                for (int i = 1; i < carts.Count(); i++)
                {
                    var items = db.CartItems.Where(x => x.CartId == carts[i].Id && x.CartId != cart.Id && x.IsActive == true).ToList();
                    foreach (var it in items)
                    {
                        it.CartId = cart.Id;
                    }
                    try
                    {
                        db.Entry(items).State = EntityState.Modified;
                        db.SaveChanges();
                        var allcarts = db.Carts.Where(x => x.IsActive == true && x.CartItems.Count() == 0).Include(x => x.CartItems).ToList();
                        //allcarts.RemoveAll(x => x.Id > 0);
                        db.Entry(allcarts).State = EntityState.Deleted;
                        db.SaveChanges();
                    }
                    catch (Exception ex)
                    { }
                }
            }
            else if (carts.Count() == 1)
            {
                cart = carts[0];
            }


            foreach (var c in cart.CartItems.Where(m => m.IsActive == true))
            {
                c.ProductVariantDetail = db.ProductVariantDetails.Where(x => x.IsActive == true && x.Id == c.ProductVariantDetailId)
                                         .Include(x => x.Product)
                                         .Include(x => x.ProductVariantOptions)
                                         .Include(x => x.ProductImages).FirstOrDefault().RemoveReferences();
            }


            var cartitems = new List <GetCart>();
            var newitems  = cart.CartItems.Where(x => x.IsActive == true).ToList();

            //newitems = DealHelper.calculateDeal(newitems, db);
            foreach (var c in newitems)
            {
                var model = new GetCart();
                model.AdditionalCost = cart.AdditionalCost;
                model.ProductId      = Convert.ToInt32(c.ProductVariantDetail?.ProductId);
                model.Id             = cart.Id;
                if (c.ProductVariantDetail?.ProductImages.Count > 0)
                {
                    model.Image150 = c.ProductVariantDetail?.ProductImages.Where(x => x.IsDefault == true && x.IsActive == true).FirstOrDefault() == null ?
                                     (c.ProductVariantDetail.ProductImages.Where(x => x.IsActive == true).FirstOrDefault().ImagePath150x150 == null? c.ProductVariantDetail.ProductImages.Where(x => x.IsActive == true).FirstOrDefault().ImagePath: c.ProductVariantDetail.ProductImages.Where(x => x.IsActive == true).FirstOrDefault().ImagePath150x150)
                        :(c.ProductVariantDetail.ProductImages.Where(x => x.IsDefault == true && x.IsActive == true).FirstOrDefault().ImagePath150x150 == null? c.ProductVariantDetail.ProductImages.Where(x => x.IsDefault == true && x.IsActive == true).FirstOrDefault().ImagePath: c.ProductVariantDetail.ProductImages.Where(x => x.IsDefault == true && x.IsActive == true).FirstOrDefault().ImagePath150x150);
                }
                model.InStock      = Convert.ToInt32(c.ProductVariantDetail?.InStock);
                model.SellingPrice = Convert.ToInt32(c.ProductVariantDetail.Price);
                var p     = Convert.ToInt32(db.ProductVariantDetails.Where(x => x.Id == c.ProductVariantDetailId).Include(x => x.Product.ProductCategory).FirstOrDefault().Product?.ProductCategory?.ParentId);
                var catid = getparentCat(p);
                model.Commission          = GetCommissionByCategoryId(catid);
                model.Discount            = Convert.ToInt32(c.ProductVariantDetail.Discount);
                model.IpAddress           = cart.IpAddress;
                model.IsConvertToCheckout = cart.IsConvertToCheckout;
                model.Name                   = c.ProductVariantDetail?.Product?.Name;
                model.OrderDate              = cart.OrderDate;
                model.OrderNumber            = cart.OrderNumber;
                model.UserId                 = cart.UserId;
                model.ProductVariantDetailId = c.ProductVariantDetailId;
                if (c.ProductVariantDetail?.ProductVariantOptions != null)
                {
                    foreach (var v in c.ProductVariantDetail?.ProductVariantOptions.Where(x => x.IsActive == true))
                    {
                        var variantid = v.VariantOptionId;
                        var variantop = new VariantOption();
                        variantop = db.VariantOptions.Where(x => x.IsActive == true && x.Id == variantid).Include(x => x.Variant).FirstOrDefault().RemoveReferences();
                        var variantmodel = new VariantOptionModel();
                        variantmodel.Id          = variantop.Id;
                        variantmodel.Name        = variantop.Name;
                        variantmodel.VariantId   = variantop.VariantId;
                        variantmodel.varientName = variantop.Variant?.Name;
                        model.VariantOptions.Add(variantmodel);
                    }
                }
                model.Quantity   = c.Quantity;
                model.CartItemId = c.Id;
                if (c.ProductVariantDetail?.Product.VendorId > 0)
                {
                    var vendor = vendors.Where(v => v.Id == c.ProductVariantDetail?.Product?.VendorId && v.RoleId == (int)RoleType.Vendor).FirstOrDefault();
                    if (vendor != null)
                    {
                        model.VendorName = vendor.DisplayName;
                    }
                }
                cartitems.Add(model);
            }

            cartitems = DealHelper.calculateDeal(cartitems, db);
            cartitems = PriceIncrementHelper.calculatePrice(cartitems, db);
            cartitems = SpinnerPromotion(cartitems, CustomerId);
            return(cartitems);


            var getCart = new List <GetCart>();

            return(getCart);
        }