/// <summary> /// Converts a rule obtained from db into a compile-able predicate /// </summary> /// <param name="rule">the rule entity to be converted into expression</param> /// <param name="ruleInstance">the name of the rule instance to register this rule with</param> /// <returns>The compileable expression</returns> public static Expression <Func <T, bool> > GenerateExpression(PaymentRule rule, out string ruleInstance) { // extract the name of the property to match var prop = typeof(T).GetProperty(rule.Parameter); if (prop != null) { // generate the parameter to match. This name can be anything, but it should be of the generic type. // This ensures that our expression has some amount of type safety var parameter = Expression.Parameter(typeof(T), "prop"); // generate the left expression from the parameter var leftExpression = Expression.Property(parameter, rule.Parameter); // generate the constant expression to match against var constantExpression = Expression.Constant(rule.Constant, typeof(string)); // check if the expression can be parsed if (ExpressionType.TryParse(rule.Operation, out ExpressionType operation)) { var expression = Expression.MakeBinary(operation, leftExpression, constantExpression); ruleInstance = rule.RuleInstance; return(Expression.Lambda <Func <T, bool> >(expression, parameter)); } ruleInstance = null; return(null); } ruleInstance = null; return(null); }
public IEnumerable <VmPaymentRule> GetPaymentRulesByFilter(VmPaymentRule filterItem) { var paymentRuleRepository = UnitOfWork.GetRepository <PaymentRuleRepository>(); var viewFilterItem = new PaymentRule { Id = filterItem.Id, TypeOfRegistration = filterItem.TypeOfRegistration, FirstTeamFee = filterItem.FirstTeamFee, ExtraTeamDiscount = filterItem.ExtraTeamDiscount, DueDate = DateTime.Parse(filterItem.DueDate ?? "1/1/0001"), DueDatePrefix = filterItem.DueDatePrefix, }; var paymentRuleList = paymentRuleRepository.Select(viewFilterItem, 0, int.MaxValue); var vmPaymentRuleList = from paymentRule in paymentRuleList select new VmPaymentRule { Id = paymentRule.Id, TypeOfRegistration = paymentRule.TypeOfRegistration, FirstTeamFee = paymentRule.FirstTeamFee, ExtraTeamDiscount = paymentRule.ExtraTeamDiscount, DueDate = paymentRule.DueDate.ToString(), DueDatePrefix = paymentRule.DueDatePrefix, }; return(vmPaymentRuleList); }
// If the payment is for a physical product, generate a package slip for shipping public void GenerateDummyRuleForASPBook(PlanDay.Assignment.Data.EFConcrete.TestDataContext context) { if (context.PaymentRules.Count(p => p.Name.Equals("If the payment is for a book, create a duplicate packing slip for the royalty department")) > 0) { return; } PaymentRule paymentRuleForAspBookProduct = new PaymentRule(new PaymentRuleHandler()); paymentRuleForAspBookProduct.Name = "If the payment is for a book, create a duplicate packing slip for the royalty department"; Criteria criteria = new Criteria(new CriteriaRuleHandler()); criteria.CriteriaType = CriteriaType.ProductTag; criteria.CriteriaOperator = CriteriaOperator.Equal; criteria.ChainedCriteria = ChainedCriteria.And; criteria.PaymentRule = paymentRuleForAspBookProduct; criteria.Value = "2"; // Physical Tag Id paymentRuleForAspBookProduct.Criterias = new List <Criteria>(); paymentRuleForAspBookProduct.Criterias.Add(criteria); paymentRuleForAspBookProduct.Actions = new List <Core.PaymentRule.Action>(); paymentRuleForAspBookProduct.Actions.Add(new Core.PaymentRule.Action { Name = "Generate a second package slip for loyalty department", PaymentRule = paymentRuleForAspBookProduct, Type = typeof(PackageSlip).ToString() }); // save in DB context.PaymentRules.Add(paymentRuleForAspBookProduct); context.SaveChanges(); }
public int CreatePaymentRule(VmPaymentRule vmPaymentRule) { var result = -1; try { var paymentRuleRepository = UnitOfWork.GetRepository <PaymentRuleRepository>(); var newPaymentRule = new PaymentRule { Id = vmPaymentRule.Id, TypeOfRegistration = vmPaymentRule.TypeOfRegistration, FirstTeamFee = vmPaymentRule.FirstTeamFee, ExtraTeamDiscount = vmPaymentRule.ExtraTeamDiscount, DueDate = DateTime.Parse(vmPaymentRule.DueDate), DueDatePrefix = vmPaymentRule.DueDatePrefix, }; paymentRuleRepository.CreatePaymentRule(newPaymentRule); UnitOfWork.Commit(); result = newPaymentRule.Id; } catch (Exception ex) { result = -1; } return(result); }
// If the payment is for a physical product, generate a package slip for shipping public void GenerateDummyRuleForPhysicalProduct(PlanDay.Assignment.Data.EFConcrete.TestDataContext context) { if (context.PaymentRules.Count(p => p.Name.Equals("If the payment is for a physical product, generate a package slip for shipping")) > 0) { return; } // PaymentRule paymentRuleForPhysicalProduct = new PaymentRule(new PaymentRuleHandler()); paymentRuleForPhysicalProduct.Name = "If the payment is for a physical product, generate a package slip for shipping"; Criteria criteria = new Criteria(new CriteriaRuleHandler()); criteria.CriteriaType = CriteriaType.ProductTag; criteria.CriteriaOperator = CriteriaOperator.Equal; criteria.ChainedCriteria = ChainedCriteria.And; criteria.PaymentRule = paymentRuleForPhysicalProduct; criteria.Value = "1"; // Physical Tag Id paymentRuleForPhysicalProduct.Criterias = new List <Criteria>(); paymentRuleForPhysicalProduct.Criterias.Add(criteria); paymentRuleForPhysicalProduct.Actions = new List <Core.PaymentRule.Action>(); paymentRuleForPhysicalProduct.Actions.Add(new Core.PaymentRule.Action { Name = "Generate a package slip", PaymentRule = paymentRuleForPhysicalProduct, Type = typeof(PackageSlip).ToString() }); // save in DB context.PaymentRules.Add(paymentRuleForPhysicalProduct); context.SaveChanges(); }
public void DeletePaymentRule(IPaymentRule paymentRule) { PaymentRule payRule = (PaymentRule)paymentRule; Supplier supp = (Supplier)payRule.Supplier; supp.DeletePaymentRule(payRule); }
public Tax(int year, TaxRule tRule, PaymentRule pRule) { Year = year > 2000 ? year : throw new ArgumentOutOfRangeException(nameof(year)); tRule = tRule != null ? tRule : throw new ArgumentOutOfRangeException(nameof(tRule)); Year = year; TRule = tRule; PRule = pRule; }
public VmPaymentRule GetPaymentRuleBySuitableDueDate(DateTime dueDate) { var paymentRuleRepository = UnitOfWork.GetRepository <PaymentRuleRepository>(); PaymentRule paymentRule = paymentRuleRepository.GetPaymentRuleByDueDate(dueDate); if (paymentRule == null) { var paymentRuleList = paymentRuleRepository.GetPaymentRuleBySuitableDueDate(); var maxDueDate = paymentRuleList.Max(i => i.DueDate); if (dueDate > maxDueDate) { return(null); } var minDueDate = paymentRuleList.Min(i => i.DueDate); if (dueDate <= minDueDate) { return((from s in paymentRuleList where s.DueDate == minDueDate select new VmPaymentRule { Id = s.Id, TypeOfRegistration = s.TypeOfRegistration, FirstTeamFee = s.FirstTeamFee, ExtraTeamDiscount = s.ExtraTeamDiscount, DueDate = s.DueDate.ToString(), DueDatePrefix = s.DueDatePrefix, }).FirstOrDefault()); } else { paymentRule = BinarySearchRecursive(paymentRuleList, dueDate, 0, paymentRuleList.Count - 1); } } VmPaymentRule vmPaymentRule = null; if (paymentRule != null) { vmPaymentRule = new VmPaymentRule { Id = paymentRule.Id, TypeOfRegistration = paymentRule.TypeOfRegistration, FirstTeamFee = paymentRule.FirstTeamFee, ExtraTeamDiscount = paymentRule.ExtraTeamDiscount, DueDate = paymentRule.DueDate.ToString(), DueDatePrefix = paymentRule.DueDatePrefix, }; } return(vmPaymentRule); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var account = AccountDataStore.GetAccount(request.DebtorAccountNumber); var paymentRule = PaymentRule.GetPaymentRule(request.PaymentScheme); if (paymentRule.IsValid(account, request)) { account.Balance -= request.Amount; AccountDataStore.UpdateAccount(account); return(new MakePaymentResult() { Success = true }); } return(new MakePaymentResult()); }
public bool UpdatePaymentRule(VmPaymentRule vmPaymentRule) { var PaymentRuleRepository = UnitOfWork.GetRepository <PaymentRuleRepository>(); var updateablePaymentRule = new PaymentRule { Id = vmPaymentRule.Id, TypeOfRegistration = vmPaymentRule.TypeOfRegistration, FirstTeamFee = vmPaymentRule.FirstTeamFee, ExtraTeamDiscount = vmPaymentRule.ExtraTeamDiscount, DueDate = DateTime.Parse(vmPaymentRule.DueDate), DueDatePrefix = vmPaymentRule.DueDatePrefix, }; PaymentRuleRepository.UpdatePaymentRule(updateablePaymentRule); return(UnitOfWork.Commit()); }
public void Cleanup() { sut = null; }
public void Initialize() { sut = new PaymentRule(new PaymentRuleHandler()); sut.Criterias = new List <Criteria>(); sut.Actions = new List <PlanDay.Assignment.Core.PaymentRule.Action>(); }