public async Task <IActionResult> GetAllFestivals(int fest) { try { var AllFests = ((List <FestivalOfferModel>)(await _festivalrepo.GetAll()).Data).Where(x => x.F_IsDeleted == false).ToList(); List <object> Result = new List <object>(); foreach (var item in AllFests) { if (item.F_Type == 1) ///is for all products { Result.Add(new { Id = item.F_Id, Type = item.F_Type, Title = item.F_Title, Discount = item.F_Discount, TypeStr = "همه محصولات", Status = item.F_Status, }); } else { var cat = await _productcatrepo.GetById(item.F_EndLevelCategoryId); if (cat != null) { Result.Add(new { Id = item.F_Id, Type = item.F_Type, Title = item.F_Title, Discount = item.F_Discount, TypeStr = cat.PC_Title, Status = item.F_Status, CategoryId = cat.PC_Id, CategoryTitle = cat.PC_Title }); } } } return(new JsonResult(ResponseModel.Success(data: Result))); } catch (Exception ex) { return(new JsonResult(ResponseModel.ServerInternalError(data: ex))); } }
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()); } }