public async Task <ProductCombineModel> GetById(object id) { try { var allCombines = ((List <ProductCombineModel>)(await GetAll()).Data); var entity = allCombines.FirstOrDefault(x => x.X_Id == int.Parse(id.ToString())); if (entity != null) { var color = this._context.Color.FirstOrDefault(x => x.C_Id == entity.X_ColorId); var warranty = this._context.Warranty.FirstOrDefault(x => x.W_Id == entity.X_WarrantyId); if (color != null) { entity.ColorDetail = color; } if (warranty != null) { entity.WarrantyModel = warranty; } var p = _context.Product.FirstOrDefault(x => x.P_Id == entity.X_ProductId); entity.PriceModel = await _pCalcRepository.CalculateProductCombinePrice(entity.X_Id, p.P_EndLevelCatId); } return(entity); } catch (Exception ex) { return(null); } }
public async Task <List <PromotionBoxModel> > GetByType(int Type) { try { var opt = ((List <OptionsModel>)(await _optionrepo.GetAll()).Data).FirstOrDefault(x => x.O_Key == "DELETEDISCOUNTS"); bool isActive = bool.Parse(opt.O_Value); var optSpecial = ((List <OptionsModel>)(await _optionrepo.GetAll()).Data).FirstOrDefault(x => x.O_Key == "SPECIALSALESTATE"); bool isActiveSpecial = bool.Parse(optSpecial.O_Value); var AllPromotions = ((List <PromotionBoxModel>)(await GetAll()).Data).Where(x => x.B_Type == Type).ToList(); if ((isActive && Type == 6)) { return(null); } if ((!isActiveSpecial && Type == 6)) { return(null); } foreach (var box in AllPromotions) { foreach (var item in _context.PromotionBoxProducts.Where(x => x.X_SectionId == box.B_SectionId)) { var p = _context.Product.FirstOrDefault(x => x.P_Id == item.X_ProdId); if (Type == 6) { p.P_Title = item.X_ProdTitle; } var combine = _context.ProductCombine.FirstOrDefault(x => x.X_ColorId == item.X_ColorId && x.X_WarrantyId == item.X_WarrantyId && x.X_ProductId == item.X_ProdId); if (combine != null) { combine.PriceModel = await _pcalcrepo.CalculateProductCombinePrice(combine.X_Id, p.P_EndLevelCatId); p.DefaultProductCombine = combine; if (p != null) { box.Products.Add(p); } } } } return(AllPromotions); } catch (Exception ex) { return(new List <PromotionBoxModel>()); } }
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))); } }
public async Task <BasketViewModel> GetBasketItems(HttpRequest httpRequest) { try { BasketViewModel basketView = new BasketViewModel(); string cookie; if (httpRequest.Cookies.TryGetValue("Cart", out cookie)) { if (cookie != null) { FullPropertyBasketModel BasketModel = new FullPropertyBasketModel(); var basketInfo = Barayand.Common.Services.CryptoJsService.DecryptStringAES(cookie); BasketModel = JsonConvert.DeserializeObject <FullPropertyBasketModel>(basketInfo); decimal SumWithDiscount = 0; decimal SumWithOutDiscount = 0; if (BasketModel.CartItems.Count() > 0) { List <ProductList> productLists = new List <ProductList>(); foreach (var item in BasketModel.CartItems) { ProductList productList = new ProductList(); if (item.ProductType == 1)//item is product combine { var productcomine = await _productcombinerepo.GetById(item.ProductCombineId); if (productcomine != null) { ProductModel product = await _productrepo.GetById(productcomine.X_ProductId); if (product != null) { var priceModel = await _priceCalculator.CalculateProductCombinePrice(productcomine.X_Id, product.P_EndLevelCatId); productList.ProductTitle = product.P_Title; productList.ProductImage = product.P_Image; productList.ProductCombineId = productcomine.X_Id; productList.Quantity = item.Quantity; productList.Price = priceModel.Price; productList.DiscountedPrice = priceModel.DiscountedPrice; if (priceModel.HasDiscount) { productList.Total = (productList.DiscountedPrice * item.Quantity); SumWithDiscount += productList.Total; } else { productList.Total = (productList.Price * item.Quantity); if (!await _priceCalculator.checkProductCombineExistsDiscount(item.ProductCombineId, product.P_EndLevelCatId)) { SumWithOutDiscount += productList.Total; } } productList.IsAvailable = (productcomine.X_AvailableCount >= item.Quantity); productList.ColorTitle = productcomine.ColorDetail.C_Title; productList.WarrantyTitle = productcomine.WarrantyModel.W_Title; productList.GiftProduct = product.Gift; productLists.Add(productList); } } } else//item is product manual { var manual = await _productmanualrepo.GetById(item.ProductCombineId); if (manual != null) { var product = await _productrepo.GetById(manual.M_ProductId); if (product != null) { productList.ProductTitle = manual.M_Title + "-" + product.P_Title; productList.ProductImage = product.P_Image; productList.ProductCombineId = 0; productList.Quantity = item.Quantity; productList.Price = manual.M_Price; productList.DiscountedPrice = 0; productList.Total = (productList.Price * item.Quantity); productList.ColorTitle = "---"; productList.WarrantyTitle = "---"; productList.GiftProduct = null; productLists.Add(productList); } } } } basketView.Products.AddRange(productLists); basketView.ReciptientInfo = BasketModel.RecipientInfo; if (BasketModel.Coppon.Count() > 0) { var c = BasketModel.Coppon.FirstOrDefault(); if (SumWithOutDiscount > 0) { var clc = (SumWithOutDiscount - c.CP_Discount); clc = clc < 0 ? 0 : clc; BasketModel.Total = clc + SumWithDiscount; } else { BasketModel.Total = SumWithDiscount; } var coupunAmount = c.CP_Discount; basketView.CouponInfo = new Coupon() { CouponAmount = coupunAmount, CouponDiscount = c.CP_Discount, CouponId = c.CP_Code }; } else { BasketModel.Total = SumWithDiscount + SumWithOutDiscount; } basketView.Total = BasketModel.Total; } } } return(basketView); } catch (Exception ex) { return(new BasketViewModel()); } }