Example #1
0
        public product7 allProducts(int Id, string name, int orderNumber)
        {
            var      eachPrd = new product7();
            product7 _prd    = new product7();

            try
            {
                var data = db.Products.Where(x => x.IsActive == true && x.IsEnable == true && x.Id == Id)
                           .Include(c => c.ProductVariantDetails)
                           .Include(x => x.RatingReviews)
                           .Include(x => x.ProductImages).OrderByDescending(x => x.Id).FirstOrDefault();
                if (data != null)
                {
                    eachPrd.listName  = name;
                    eachPrd.listOrder = orderNumber;
                    eachPrd.Id        = data.Id;
                    if (data.ProductImages.Count() != 0)
                    {
                        eachPrd.Url    = data.ProductImages?.FirstOrDefault().ImagePath;
                        eachPrd.Url150 = data.ProductImages?.FirstOrDefault().ImagePath150x150;
                        eachPrd.Url450 = data.ProductImages?.FirstOrDefault().ImagePath450x450;
                    }
                    eachPrd.Rating            = data.RatingReviews.Select(x => x.Rating).FirstOrDefault();
                    eachPrd.Description       = data.Description;
                    eachPrd.Name              = data.Name;
                    eachPrd.ShipmentVendor    = data.ShipmentVendor ?? false;
                    eachPrd.ShipmentTime      = data.ShipmentTime ?? 0;
                    eachPrd.ShipmentCost      = data.ShipmentCost ?? 0;
                    eachPrd.ProductCategoryId = data.ProductCategoryId;
                    if (data.ProductVariantDetails.Where(c => c.IsActive == true).Any(c => c.IsDefault == true))
                    {
                        eachPrd.LandingVariant = data.ProductVariantDetails.Where(c => c.IsActive == true).Where(c => c.IsDefault == true && c.IsActive == true).Select(d => new ProductVariantDetailModel
                        {
                            Id                 = d.Id,
                            Price              = d.Price,
                            Discount           = d.Discount,
                            PriceAfterdiscount = d.PriceAfterdiscount,
                            InStock            = d.InStock,
                        }).FirstOrDefault();
                    }
                    else
                    {
                        eachPrd.LandingVariant = data.ProductVariantDetails.Where(c => c.IsActive == true).Select(d => new ProductVariantDetailModel
                        {
                            Id                 = d.Id,
                            Price              = d.Price,
                            Discount           = d.Discount,
                            PriceAfterdiscount = d.PriceAfterdiscount,
                            InStock            = d.InStock,
                        }).FirstOrDefault();
                    }
                    if (eachPrd.LandingVariant != null)
                    {
                        eachPrd.SellingPrice       = eachPrd.LandingVariant.Price;
                        eachPrd.Discount           = eachPrd.LandingVariant.Discount;
                        eachPrd.PriceAfterdiscount = eachPrd.LandingVariant.PriceAfterdiscount;
                        eachPrd.InStock            = eachPrd.LandingVariant.InStock;

                        var img = data.ProductImages.Where(c => c.ProductId == eachPrd.Id && c.ProductVariantDetailId == eachPrd.LandingVariant.Id && c.IsActive == true).ToList();
                        if (img.Any(c => c.IsDefault == true))
                        {
                            eachPrd.Url    = img.Where(c => c.IsDefault == true).FirstOrDefault().ImagePath;
                            eachPrd.Url150 = img.Where(c => c.IsDefault == true).FirstOrDefault().ImagePath150x150;
                            eachPrd.Url450 = img.Where(c => c.IsDefault == true).FirstOrDefault().ImagePath450x450;
                        }
                        else
                        {
                            eachPrd.Url    = img.FirstOrDefault().ImagePath;
                            eachPrd.Url150 = img.FirstOrDefault().ImagePath150x150;
                            eachPrd.Url450 = img.FirstOrDefault().ImagePath450x450;
                        }
                    }


                    eachPrd.VariantDetailId = eachPrd.LandingVariant.Id;

                    eachPrd = DealHelper.calculateDealForProducts(eachPrd, db);
                    eachPrd = PriceIncrementHelper.calculatePriceForProducts(eachPrd, db);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(eachPrd);
        }
Example #2
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);
        }