private FetchAccountBusinessRules(FetchAccountBusinessRules abr)
 {
     TotalBilledAmount = abr.TotalBilledAmount;
     Client            = abr.Client;
     PortfolioName     = abr.PortfolioName;
     AccountState      = abr.AccountState;
     Command           = abr.Command;
     AccountRef        = abr.AccountRef;
 }
        GetAccountBusinessRulesForCommand(FetchAccountBusinessRules cmd)
        {
            //_logger.Info($"[GetAccountBusinessRulesForCommand]: Getting business rules for {cmd.AccountState.AccountNumber}.");
            if (RulesInFile == null)
            {
                Initialize();
            }
            try
            {
                var rules = RulesInFile
                            .Where(ruleMap =>
                                   // Look for rules associated to this command
                                   ruleMap.Command.GetType().Name.Equals(cmd.Command.GetType().Name) &&
                                   // which also either match this account
                                   (ruleMap.AccountNumber.Equals(cmd.AccountState.AccountNumber) ||
                                   // or all accounts under this portfolio
                                    ruleMap.Portfolio.Equals(cmd.PortfolioName) && ruleMap.ForAllAccounts ||
                                   // or all accounts under all portfolios for this client
                                    ruleMap.Client.Equals(cmd.Client) && ruleMap.Portfolio.Equals("*") &&
                                    ruleMap.ForAllAccounts)
                                   )
                            .Select(ruleMap => ruleMap.BusinessRule).ToImmutableList();

                var rulesFound = new List <IAccountBusinessRule>();

                rulesFound.AddRange(rules.ToList());
                // TODO need to make this dynamic using replection
                //And lastly add the command rule itself
                rulesFound.Add(new BillingAssessmentRule());

                AccountBusinessRulesHandlerRouter.Tell(
                    new MappedBusinessRules(cmd, rulesFound.ToList())
                    );
            }
            catch (Exception e)
            {
                _logger.Error($"{e.Message} {e.StackTrace}");
                throw;
            }
        }
 public MappedBusinessRules(FetchAccountBusinessRules fetchAccountBusinessRules, List <IAccountBusinessRule> rules)
 {
     FetchAccountBusinessRules = fetchAccountBusinessRules;
     Rules = rules;
 }
 public GetBusinessRulesToApply(FetchAccountBusinessRules fetchAccountBusinessRules)
 {
     FetchAccountBusinessRules = fetchAccountBusinessRules;
 }