public static List <Products> GettheProductClassification(List <string> adProducts) { List <Products> ProductList = new List <Products>(); try { var adProductsGrouped = adProducts.GroupBy(s => s); using (WOLFCOMTechnicalTestEntities db = new WOLFCOMTechnicalTestEntities()) { foreach (var adProduct in adProductsGrouped) { var product = db.ProductDetails.FirstOrDefault(x => x.ProductId == adProduct.Key.Trim() && x.Status == true); if (product != null) { ProductList.Add(new Products(product, adProduct.Count())); } } } } catch (Exception ex) { logger.Error("This is an error message" + ex); throw ex; } return(ProductList); }
/// <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); }
public List <SelectListItem> GetUserPrivilages() { List <SelectListItem> Result = new List <SelectListItem>(); try { using (WOLFCOMTechnicalTestEntities db = new WOLFCOMTechnicalTestEntities()) { var PrivilageCustomers = db.PrivilageCustomers.Where(x => x.Status == true).ToList(); foreach (var PrivilageCustomer in PrivilageCustomers) { Result.Add(new SelectListItem { Text = PrivilageCustomer.CustomerPrivilageName, Value = PrivilageCustomer.CustomerId.ToString() }); } } } catch (Exception ex) { logger.Error("This is an error message" + ex); throw ex; } return(Result); }