public void Can_save_and_load_discountRequirement() { var discountRequirement = new DiscountRequirement { DiscountRequirementRuleSystemName = "BillingCountryIs", Discount = GetTestDiscount() }; var fromDb = SaveAndLoadEntity(discountRequirement); fromDb.ShouldNotBeNull(); fromDb.DiscountRequirementRuleSystemName.ShouldEqual("BillingCountryIs"); fromDb.Discount.ShouldNotBeNull(); fromDb.Discount.Name.ShouldEqual("Discount 1"); }
public ActionResult Configure(int discountId, int? discountRequirementId, decimal spentAmount) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageDiscounts)) return Content("Access denied"); var discount = _discountService.GetDiscountById(discountId); if (discount == null) throw new ArgumentException("Discount could not be loaded"); DiscountRequirement discountRequirement = null; if (discountRequirementId.HasValue) discountRequirement = discount.DiscountRequirements.FirstOrDefault(dr => dr.Id == discountRequirementId.Value); if (discountRequirement != null) { //update existing rule _settingService.SetSetting(string.Format("DiscountRequirement.HadSpentAmount-{0}", discountRequirement.Id), spentAmount); } else { //save new rule discountRequirement = new DiscountRequirement() { DiscountRequirementRuleSystemName = "DiscountRequirement.HadSpentAmount" }; discount.DiscountRequirements.Add(discountRequirement); _discountService.UpdateDiscount(discount); _settingService.SetSetting(string.Format("DiscountRequirement.HadSpentAmount-{0}", discountRequirement.Id), spentAmount); } return Json(new { Result = true, NewRequirementId = discountRequirement.Id }, JsonRequestBehavior.AllowGet); }
/// <summary> /// Delete discount requirement /// </summary> /// <param name="discountRequirement">Discount requirement</param> public virtual void DeleteDiscountRequirement(DiscountRequirement discountRequirement) { if (discountRequirement == null) throw new ArgumentNullException("discountRequirement"); _discountRequirementRepository.Delete(discountRequirement); _cacheManager.RemoveByPattern(DISCOUNTS_PATTERN_KEY); //event notification _eventPublisher.EntityDeleted(discountRequirement); }