예제 #1
0
        public async Task <bool> checkProductCombineExistsDiscount(int cid, int EndLevelCatId = 0)
        {
            try
            {
                if (RemoveDiscounts)
                {
                    return(false);
                }
                ProductCombinePriceModel PriceModel = new ProductCombinePriceModel();
                var existsCombine = _context.ProductCombine.FirstOrDefault(x => x.X_Id == cid);
                if (existsCombine != null)
                {
                    List <FestivalOfferModel> AllFestivalRepo = ((List <FestivalOfferModel>)(await _festrepo.GetAll()).Data);
                    var existsInBox = await _boxProdRepository.CheckProductCombineExistsInBox(existsCombine.X_ProductId, existsCombine.X_WarrantyId, existsCombine.X_ColorId);

                    if (existsInBox != null)
                    {
                        var defaultCombine = existsCombine;

                        PriceModel.Price = defaultCombine.X_Price;
                        if (existsInBox.X_SectionId == 34 && (DateTime.Now >= existsInBox.X_StartDate && DateTime.Now <= existsInBox.X_EndDate)) //is special sale and timer started
                        {
                            if (existsInBox.X_DiscountedPrice > 0)                                                                               //has discount
                            {
                                return(true);
                            }
                        }

                        if (existsInBox.X_SectionId != 34)
                        {
                            if (existsInBox.X_DiscountedPrice > 0)//has discount
                            {
                                return(true);
                            }
                        }
                    }
                    else if (AllFestivalRepo.Count(x => x.F_Type == 1 && x.F_Status) > 0)
                    {
                        return(true);
                    }
                    else if (EndLevelCatId != 0 && AllFestivalRepo.Count(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId) > 0)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(true);
            }
        }
        private async Task <ProductCombineModel> CalculateDefaultCombine(int pid, decimal discount = 0)
        {
            ProductCombineModel ProductCombine = new ProductCombineModel();

            try
            {
                ProductCombinePriceModel PriceModel = new ProductCombinePriceModel();
                //product not exists in boxs
                var getAllCombines = ((List <ProductCombineModel>)(await _combinerepo.GetAll()).Data).Where(x => x.X_ProductId == pid && x.X_Status && !x.X_IsDeleted);
                if (getAllCombines.Count() > 0)//combines set for current product
                {
                    var defaultCombine = getAllCombines.FirstOrDefault(x => x.X_Default);
                    if (defaultCombine != null)//has default combine
                    {
                        ProductCombine   = defaultCombine;
                        PriceModel.Price = defaultCombine.X_Price;
                        if (discount != 0)
                        {
                            defaultCombine.X_Discount     = discount;
                            defaultCombine.X_DiscountType = 1;
                        }
                        if (defaultCombine.X_Discount > 0)//has discount
                        {
                            PriceModel.HasDiscount = true;
                            if (defaultCombine.X_DiscountType == 1) // please calculate price by percentage
                            {
                                PriceModel.Discount        = defaultCombine.X_Discount;
                                PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * defaultCombine.X_Discount) / 100));
                            }
                            else//calculate percentage by price
                            {
                                PriceModel.Discount        = ((defaultCombine.X_Discount * 100) / defaultCombine.X_Price);
                                PriceModel.DiscountedPrice = defaultCombine.X_Discount;
                            }
                        }
                    }
                }
                ProductCombine.PriceModel = PriceModel;
                return(ProductCombine);
            }
            catch (Exception ex)
            {
                return(ProductCombine);
            }
        }
예제 #3
0
        public async Task <JsonResult> GetPriceAjax(int id, int garanty, int color)
        {
            try
            {
                var combine = ((List <ProductCombineModel>)(await _Combine.GetAll()).Data).FirstOrDefault(x => x.X_ColorId == color && x.X_WarrantyId == garanty && x.X_ProductId == id && x.X_IsDeleted != true && x.X_Status);
                var product = await _productrepo.GetById(combine.X_ProductId);

                ProductCombinePriceModel priceModel = await _PCalcRepository.CalculateProductCombinePrice(combine.X_Id, product.P_EndLevelCatId);

                return(new JsonResult(ResponseModel.Success(data: new
                {
                    id = combine.X_Id,
                    priceModel = priceModel
                })));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ResponseModel.ServerInternalError(data: ex)));
            }
        }
예제 #4
0
        private async Task <ProductCombineModel> SetDiscountByCombine(ProductCombineModel defaultCombine, decimal discount = 0)
        {
            ProductCombineModel ProductCombine = defaultCombine;

            try
            {
                ProductCombinePriceModel PriceModel = new ProductCombinePriceModel();
                //product not exists in boxs
                PriceModel.Price = defaultCombine.X_Price;
                if (discount != 0)
                {
                    defaultCombine.X_Discount     = discount;
                    defaultCombine.X_DiscountType = 1;
                }
                if (defaultCombine.X_Discount > 0 && !RemoveDiscounts)//has discount
                {
                    PriceModel.HasDiscount = true;
                    if (defaultCombine.X_DiscountType == 1) // please calculate price by percentage
                    {
                        PriceModel.Discount        = defaultCombine.X_Discount;
                        PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * defaultCombine.X_Discount) / 100));
                    }
                    else//calculate percentage by price
                    {
                        var disc = ((defaultCombine.X_Discount * 100) / defaultCombine.X_Price);
                        PriceModel.Discount        = (100 - disc);
                        PriceModel.DiscountedPrice = defaultCombine.X_Discount;
                    }
                }


                ProductCombine.PriceModel = PriceModel;
                return(ProductCombine);
            }
            catch (Exception ex)
            {
                return(ProductCombine);
            }
        }
        public async Task <ProductCombinePriceModel> CalculateProductCombinePrice(int cid, int EndLevelCatId = 0)
        {
            try
            {
                ProductCombinePriceModel PriceModel = new ProductCombinePriceModel();
                var existsCombine = await _combinerepo.GetById(cid);

                if (existsCombine != null)
                {
                    List <FestivalOfferModel> AllFestivalRepo = ((List <FestivalOfferModel>)(await _festrepo.GetAll()).Data);
                    var existsInBox = await _boxProdRepository.CheckProductCombineExistsInBox(existsCombine.X_ProductId, existsCombine.X_WarrantyId, existsCombine.X_ColorId);

                    if (existsInBox != null)
                    {
                        var defaultCombine = existsCombine;

                        PriceModel.Price = defaultCombine.X_Price;
                        if (existsInBox.X_SectionId == 34 && (DateTime.Now >= existsInBox.X_StartDate && DateTime.Now <= existsInBox.X_EndDate)) //is special sale and timer started
                        {
                            if (existsInBox.X_DiscountedPrice > 0)                                                                               //has discount
                            {
                                PriceModel.HasDiscount = true;
                                if (!existsInBox.X_DiscountType) // please calculate price by percentage
                                {
                                    PriceModel.Discount        = existsInBox.X_DiscountedPrice;
                                    PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * existsInBox.X_DiscountedPrice) / 100));
                                }
                                else//calculate percentage by price
                                {
                                    PriceModel.Discount        = ((existsInBox.X_DiscountedPrice * 100) / defaultCombine.X_Price);
                                    PriceModel.DiscountedPrice = existsInBox.X_DiscountedPrice;
                                }
                            }
                            PriceModel.Timer = existsInBox.X_EndDate.ToString("yyyy-MM-dd HH:mm:ss");
                        }

                        if (existsInBox.X_SectionId != 34)
                        {
                            if (existsInBox.X_DiscountedPrice > 0)//has discount
                            {
                                PriceModel.HasDiscount = true;
                                if (!existsInBox.X_DiscountType) // please calculate price by percentage
                                {
                                    PriceModel.Discount        = existsInBox.X_DiscountedPrice;
                                    PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * existsInBox.X_DiscountedPrice) / 100));
                                }
                                else//calculate percentage by price
                                {
                                    PriceModel.Discount        = ((existsInBox.X_DiscountedPrice * 100) / defaultCombine.X_Price);
                                    PriceModel.DiscountedPrice = existsInBox.X_DiscountedPrice;
                                }
                            }
                        }
                    }
                    else if (AllFestivalRepo.Count(x => x.F_Type == 1 && x.F_Status) > 0)
                    {
                        var fest           = AllFestivalRepo.FirstOrDefault(x => x.F_Type == 1);
                        var defaultCombine = existsCombine;
                        var cmb            = await SetDiscountByCombine(defaultCombine, fest.F_Discount);

                        PriceModel = cmb.PriceModel;
                    }
                    else if (EndLevelCatId != 0 && AllFestivalRepo.Count(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId) > 0)
                    {
                        var fest = AllFestivalRepo.FirstOrDefault(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId);
                        var cmb  = await SetDiscountByCombine(existsCombine, fest.F_Discount);

                        PriceModel = cmb.PriceModel;
                    }
                }
                return(PriceModel);
            }
            catch (Exception ex)
            {
                return(new ProductCombinePriceModel());
            }
        }
        public async Task <ProductCombineModel> CalculateProductPrice(int pid, int EndLevelCatId = 0)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en");

            ProductCombineModel ProductCombine = new ProductCombineModel();

            try
            {
                ProductCombinePriceModel  PriceModel      = new ProductCombinePriceModel();
                List <FestivalOfferModel> AllFestivalRepo = ((List <FestivalOfferModel>)(await _festrepo.GetAll()).Data);
                var existsInBox = await _boxProdRepository.CheckProductEixstsInBoxs(pid);

                //product exists in boxs
                if (existsInBox != null)
                {
                    var defaultCombine = ((List <ProductCombineModel>)(await _combinerepo.GetAll()).Data).FirstOrDefault(x => x.X_ColorId == existsInBox.X_ColorId && x.X_WarrantyId == existsInBox.X_WarrantyId);
                    if (defaultCombine == null)
                    {
                        return(await CalculateDefaultCombine(pid));
                    }

                    ProductCombine   = defaultCombine;
                    PriceModel.Price = defaultCombine.X_Price;
                    if (existsInBox.X_SectionId == 34 && (DateTime.Now >= existsInBox.X_StartDate && DateTime.Now <= existsInBox.X_EndDate)) //is special sale and timer started
                    {
                        if (existsInBox.X_DiscountedPrice > 0)                                                                               //has discount
                        {
                            PriceModel.HasDiscount = true;
                            if (!existsInBox.X_DiscountType) // please calculate price by percentage
                            {
                                PriceModel.Discount        = existsInBox.X_DiscountedPrice;
                                PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * existsInBox.X_DiscountedPrice) / 100));
                            }
                            else//calculate percentage by price
                            {
                                PriceModel.Discount        = ((existsInBox.X_DiscountedPrice * 100) / defaultCombine.X_Price);
                                PriceModel.DiscountedPrice = existsInBox.X_DiscountedPrice;
                            }
                        }
                        PriceModel.Timer = existsInBox.X_EndDate.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        return(await CalculateDefaultCombine(pid));
                    }
                    if (existsInBox.X_SectionId != 34)
                    {
                        if (existsInBox.X_DiscountedPrice > 0)//has discount
                        {
                            PriceModel.HasDiscount = true;
                            if (!existsInBox.X_DiscountType) // please calculate price by percentage
                            {
                                PriceModel.Discount        = existsInBox.X_DiscountedPrice;
                                PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * existsInBox.X_DiscountedPrice) / 100));
                            }
                            else//calculate percentage by price
                            {
                                PriceModel.Discount        = ((existsInBox.X_DiscountedPrice * 100) / defaultCombine.X_Price);
                                PriceModel.DiscountedPrice = existsInBox.X_DiscountedPrice;
                            }
                        }
                    }
                }
                else if (AllFestivalRepo.Count(x => x.F_Type == 1 && x.F_Status) > 0)
                {
                    var fest           = AllFestivalRepo.FirstOrDefault(x => x.F_Type == 1);
                    var defaultCombine = await CalculateDefaultCombine(pid);

                    return(await CalculateDefaultCombine(pid, fest.F_Discount));
                }
                else if (EndLevelCatId != 0 && AllFestivalRepo.Count(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId) > 0)
                {
                    var fest           = AllFestivalRepo.FirstOrDefault(x => x.F_Type == 2 && x.F_Status && x.F_EndLevelCategoryId == EndLevelCatId);
                    var defaultCombine = await CalculateDefaultCombine(pid);

                    return(await CalculateDefaultCombine(pid, fest.F_Discount));
                }
                else
                {
                    return(await CalculateDefaultCombine(pid));
                }
                ProductCombine.PriceModel = PriceModel;
                return(ProductCombine);
            }
            catch (Exception ex)
            {
                return(ProductCombine);
            }
        }
예제 #7
0
        private async Task <ProductCombineModel> CalculateDefaultCombine(int pid, decimal discount = 0)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB");
            ProductCombineModel ProductCombine = new ProductCombineModel();

            try
            {
                ProductCombinePriceModel PriceModel = new ProductCombinePriceModel();
                //product not exists in boxs
                var getAllCombines = _context.ProductCombine.Where(x => x.X_ProductId == pid && x.X_Status && !x.X_IsDeleted);
                if (getAllCombines.Count() > 0)//combines set for current product
                {
                    var defaultCombine = getAllCombines.FirstOrDefault(x => x.X_Default);

                    if (defaultCombine == null)
                    {
                        defaultCombine = getAllCombines.FirstOrDefault(x => x.X_Price > 0 && x.X_AvailableCount > 0);
                    }
                    if (defaultCombine != null)//has default combine
                    {
                        PriceModel.Avl = defaultCombine.X_AvailableCount;
                        if (defaultCombine.X_AvailableCount < 1)
                        {
                            var hasavl = getAllCombines.FirstOrDefault(x => x.X_AvailableCount > 0);
                            if (hasavl != null)
                            {
                                defaultCombine = hasavl;
                            }
                        }
                        ProductCombine   = defaultCombine;
                        PriceModel.Price = defaultCombine.X_Price;
                        PriceModel.Avl   = defaultCombine.X_AvailableCount;
                        if (discount != 0)
                        {
                            defaultCombine.X_Discount     = discount;
                            defaultCombine.X_DiscountType = 1;
                        }
                        if (defaultCombine.X_Discount > 0 && !RemoveDiscounts)//has discount
                        {
                            PriceModel.HasDiscount = true;
                            if (defaultCombine.X_DiscountType == 1) // please calculate price by percentage
                            {
                                PriceModel.Discount        = defaultCombine.X_Discount;
                                PriceModel.DiscountedPrice = (defaultCombine.X_Price - ((defaultCombine.X_Price * defaultCombine.X_Discount) / 100));
                            }
                            else//calculate percentage by price
                            {
                                var disc = ((defaultCombine.X_Discount * 100) / defaultCombine.X_Price);
                                PriceModel.Discount        = (100 - disc);
                                PriceModel.DiscountedPrice = defaultCombine.X_Discount;
                            }
                        }
                    }
                }
                ProductCombine.PriceModel = PriceModel;
                return(ProductCombine);
            }
            catch (Exception ex)
            {
                return(ProductCombine);
            }
        }