예제 #1
0
        private AccountState ApplyEvent(ObligationAssessedConcept occurred)
        {
            if (!Obligations.ContainsKey(occurred.ObligationNumber))
            {
                Console.WriteLine(
                    $"Account {AccountNumber} does not contain obligation {occurred.ObligationNumber}. No Action Taken.");
                throw new Exception(
                          $"Account {AccountNumber} does not contain obligation {occurred.ObligationNumber}. No Action Taken.");
            }

            var trans = new FinancialTransaction(occurred.FinancialBucket, occurred.FinancialBucket.Amount);

            Obligations[occurred.ObligationNumber].PostTransaction(trans);
            var newBalance = CurrentBalance + decimal.Parse(occurred.FinancialBucket.Amount.ToString());
            var newState   = new AccountState(
                AccountNumber,
                newBalance,
                AccountStatus,
                Obligations,
                SimulatedFields,
                AuditLog.Add(
                    new StateLog(
                        "ObligationAssessedConcept",
                        occurred.Message + " Balance After: " + ((decimal)newBalance).ToString("C"),
                        occurred.UniqueGuid(),
                        occurred.OccurredOn())
                    ),
                OpeningBalance,
                Inventroy,
                UserName,
                LastPaymentAmount,
                LastPaymentDate);

            return(newState);
        }
예제 #2
0
        /* Rule logic goes here. */
        public void RunRule()
        {
            this.EventsGenerated = new List <IEvent>();
            Obligation obligationToUse = null;

            foreach (var item in AccountState.Obligations.Values.ToImmutableList())
            {
                if (item.Status == ObligationStatus.Active)
                {
                    obligationToUse = item;
                    break;
                }
            }
            if (obligationToUse != null)
            {
                foreach (var item in LineItems)
                {
                    var @event = new ObligationAssessedConcept(obligationToUse.ObligationNumber, item.Item, item.TotalAmount);
                    this.EventsGenerated.Add(@event);
                }

                this.DetailsGenerated = "THIS WORKED";
                this.Success          = true;
            }
            else
            {
                this.DetailsGenerated = "No Acttive obligations on this account.";
                this.Success          = false;
            }
        }