Beispiel #1
0
        /*
         * public ProcessResult Process(Check check)
         * {
         *  ProcessResultBuilder builder = new ProcessResultBuilder();
         *
         *  try
         *  {
         *      if(!check.IsValid)
         *          builder.AddErrorMessage("Invalid check");
         *
         *      if(!(HasSufficientFunds(check.Amount) || _allowOverdrafts))
         *          builder
         *              .AddErrorMessage("Check bounced, Check bounced, insufficient founds an overdrafts are not allowed")
         *              .SetStatus(ProcessStatus.Bounced);
         *
         *      if(builder.HasErrorMessages)
         *          return builder.UsingBalance(_balance);
         *
         *      _balance -= check.Amount;
         *
         *      if(_balance < 0)
         *          builder.SetStatus(ProcessStatus.OverWithdrawal);
         *
         *      return builder.UsingBalance(_balance);
         *  }
         *  catch (Exception ex)
         *  {
         *      return builder
         *          .WithException(ex)
         *          .UsingBalance(_balance);
         *  }
         * }
         */

        public ProcessResult Process(Check check)
        {
            ProcessResultBuilder builder = new ProcessResultBuilder();

            if (!(HasSufficientFunds(check.Amount) || _allowOverdrafts))
            {
                builder
                .AddErrorMessage("Check bounced, Check bounced, insufficient founds an overdrafts are not allowed")
                .SetStatus(ProcessStatus.Bounced);
            }

            if (builder.HasErrorMessages)
            {
                return(builder.UsingBalance(_balance));
            }

            _balance -= check.Amount;

            if (_balance < 0)
            {
                builder.SetStatus(ProcessStatus.OverWithdrawal);
            }

            return(builder.UsingBalance(_balance));
        }
Beispiel #2
0
        public ProcessResult Process(Withdrawal withdrawal)
        {
            ProcessResultBuilder builder = new ProcessResultBuilder();

            try
            {
                if (!withdrawal.IsValid)
                {
                    builder.AddErrorMessage("Invalid withdrawal");
                }

                if (!HasSufficientFunds(withdrawal.Amount))
                {
                    builder.AddErrorMessage("You cannot withdraw more than is in the account");
                }

                if (!builder.HasErrorMessages)
                {
                    _balance -= withdrawal.Amount;
                }

                return(builder.UsingBalance(_balance));
            }
            catch (Exception ex)
            {
                return(builder
                       .WithException(ex)
                       .UsingBalance(_balance));
            }
        }
Beispiel #3
0
        public ProcessResult Process(Deposit deposit)
        {
            ProcessResultBuilder builder = new ProcessResultBuilder();

            try
            {
                if (!deposit.IsValid)
                {
                    builder.AddErrorMessage("Invalid deposit");
                }

                if (!builder.HasErrorMessages)
                {
                    _balance += deposit.Amount;
                }

                return(builder.UsingBalance(_balance));
            }
            catch (Exception ex)
            {
                return(builder
                       .WithException(ex)
                       .UsingBalance(_balance));
            }
        }
Beispiel #4
0
        public ProcessResult Process(Fee fee)
        {
            ProcessResultBuilder builder = new ProcessResultBuilder();

            try
            {
                if (!fee.IsValid)
                {
                    builder.AddErrorMessage("Invalid fee");
                }

                if (!builder.HasErrorMessages)
                {
                    _balance -= fee.Amount;
                }

                return(builder.UsingBalance(_balance));
            }
            catch (Exception ex)
            {
                return(builder
                       .WithException(ex)
                       .UsingBalance(_balance));
            }
        }