private DiscountApplicationResult GetDiscountApplication(List<DiscountInfo> discounts, CartModel cart) { var discountApplicationInfo = new DiscountApplicationInfo(); var hashSet = new List<Discount>(); foreach (var discountInfo in discounts.FindAll(x => x.Status == DiscountStatus.ValidButNotApplied)) { var applicationInfo = _cartDiscountApplicationService.ApplyDiscount(discountInfo, cart); if (!applicationInfo.IsApplied) continue; discountApplicationInfo.Add(applicationInfo); hashSet.Add(discountInfo.Discount); } return new DiscountApplicationResult { Info = discountApplicationInfo, AppliedDiscounts = hashSet }; }
public DiscountApplicationInfo ApplyDiscount(DiscountInfo discountInfo, CartModel cart) { var applications = _session.QueryOver<DiscountApplication>() .Where(application => application.Discount.Id == discountInfo.Discount.Id) .Cacheable() .List(); var discountApplicationInfo = new DiscountApplicationInfo(); foreach (var application in applications) { var fullName = application.GetType().FullName; if (!ApplicationApplierTypes.ContainsKey(fullName)) continue; var applier = _kernel.Get(ApplicationApplierTypes[fullName]) as DiscountApplicationApplier; if (applier != null) discountApplicationInfo.Add(applier.Apply(application, cart, discountInfo.CheckLimitationsResult)); } return discountApplicationInfo; }