/// <summary> /// /// </summary> /// <param name="Model"></param> /// <returns></returns> public BillCalculationResponseModel CalculatetheBilledAmount(BillRequestViewModel Model) { BillCalculationResponseModel Result = new BillCalculationResponseModel(); try { List <string> adsGroup = StringReplace.StringSplitter(Model.PurchasedAds); var PurchasedProductList = ProductClassifications.GettheProductClassification(adsGroup); if (PurchasedProductList.Count == 0) { Result.Message = "No Products found"; } decimal sumAmount = 0; using (WOLFCOMTechnicalTestEntities db = new WOLFCOMTechnicalTestEntities()) { var PrivilagePromotion = db.PrivilageCustomers.FirstOrDefault(x => x.CustomerPrivilageName == Model.UserType && x.Status == true); if (PrivilagePromotion == null || PrivilagePromotion.CustomerPromotions == null) { foreach (var PurchasedProduct in PurchasedProductList) { sumAmount += (PurchasedProduct.ProductPrice * PurchasedProduct.Count); } } else { var CustomerPromotionList = PrivilagePromotion.CustomerPromotions.Where(customerpromotion => PurchasedProductList.Any(product => product.ProductCode.Equals(customerpromotion.ProductCode)) && customerpromotion.Status == true).ToList(); sumAmount = BillCalculation.BillCalculationwithPromotion(CustomerPromotionList, PurchasedProductList); } Result.PrivilageType = Model.UserType; Result.Ads = Model.PurchasedAds; Result.TotalAmount = Math.Round(sumAmount, 2); } } catch (Exception ex) { logger.Error("This is an error message" + ex); throw ex; } return(Result); }
public BillResponseModel FindtheBilledAmount(BillViewModel Model) { BillResponseModel Result = new BillResponseModel(); Model.TotalPrice = Model.AmountPerPerson * Model.NumberofCustomers; try { if (Model.PromoCode == Constants.NonePromoCode || string.IsNullOrEmpty(Model.PromoCode)) { using (WOLFCOMTechnicalTestEntities db = new WOLFCOMTechnicalTestEntities()) { var WithoutPromoCodeList = db.PromoCodeDetails.Where(x => (x.CanAvailWithoutPromoCode == true) && (x.Status == true)).ToList(); if (WithoutPromoCodeList.Count() == 0) { return(new BillResponseModel(Model.TotalPrice)); } Result = BillCalculation.ExecuteBillCalculation(WithoutPromoCodeList, Model); } } else { using (WOLFCOMTechnicalTestEntities db = new WOLFCOMTechnicalTestEntities()) { var WithPromoCodeList = db.PromoCodeDetails.Where(x => (x.CanAvailWithoutPromoCode == true || x.PromoCode == Model.PromoCode) && (x.Status == true)).ToList(); if (WithPromoCodeList.Count() == 0) { return(new BillResponseModel(Model.TotalPrice)); } Result = BillCalculation.ExecuteBillCalculation(WithPromoCodeList, Model); } } } catch (Exception ex) { logger.Error("This is an error message" + ex); return(null); } return(Result); }