public override void HandleRequest(TransactionEditHelperModel Model)
        {
            if (!Model.IsEditOperationType)
            {
                Successor.HandleRequest(Model);
                return;
            }

            if (Model.OldScore != null && Model.OldOperationTypeId == 1 && Model.OldScore.Balance < Model.OldTransactionSum &&
                !Model.IsEditScore && !Model.IsEditSum)
            {
                throw new TransactionException("Недостаточно средств на счете!");
            }
            if (Model.NewOperationTypeId == 2 && Model.NewScore.Balance < Model.NewTransactionSum &&
                !Model.IsEditScore && !Model.IsEditSum)
            {
                throw new TransactionException("Недостаточно средств на счете!");
            }


            if (Model.OldScore == null)
            {
                Model.NewScore.Balance += Model.NewOperationTypeId == Income && Model.IsEditOperationType ? Model.NewTransactionSum * 2 : 0;
                Model.NewScore.Balance -= Model.NewOperationTypeId == Expense && Model.IsEditOperationType ? Model.NewTransactionSum * 2 : 0;
            }
            else
            {
                Model.OldScore.Balance += Model.NewOperationTypeId == Income && Model.IsEditOperationType ? Model.NewTransactionSum * 2 : 0;
                Model.OldScore.Balance -= Model.NewOperationTypeId == Expense && Model.IsEditOperationType ? Model.NewTransactionSum * 2 : 0;
            }

            Successor.HandleRequest(Model);
        }
        public override void HandleRequest(TransactionEditHelperModel Model)
        {
            if (!Model.IsEditScore)
            {
                Successor.HandleRequest(Model);
                return;
            }


            if ((Model.NewScore.Balance < Model.NewTransactionSum) && Model.NewOperationTypeId == Expense &&
                !Model.IsEditOperationType && !Model.IsEditSum)
            {
                throw new TransactionException("Недостаточно средств на счете!");
            }
            if ((Model.OldScore.Balance < Model.NewTransactionSum) && Model.NewOperationTypeId == Income &&
                !Model.IsEditOperationType && !Model.IsEditSum)
            {
                throw new TransactionException("Недостаточно средств на счете!");
            }
            if (Model.NewOperationTypeId != Income && Model.NewOperationTypeId != Expense)
            {
                throw new TransactionException("Нет такого типа операций!");
            }


            Model.OldScore.Balance -= Model.NewOperationTypeId == Income ? Model.NewTransactionSum : 0;
            Model.OldScore.Balance += Model.NewOperationTypeId == Expense ? Model.NewTransactionSum : 0;

            Model.NewScore.Balance += Model.NewOperationTypeId == Income ? Model.NewTransactionSum : 0;
            Model.NewScore.Balance -= Model.NewOperationTypeId == Expense ? Model.NewTransactionSum : 0;


            Successor.HandleRequest(Model);
        }
        public override void HandleRequest(TransactionEditHelperModel Model)
        {
            if (!Model.IsEditSum)
            {
                return;
            }

            Model.NewScore.Balance += Model.NewOperationTypeId == Income ? Model.GetTransactionDifNew_Old : 0;
            Model.NewScore.Balance -= Model.NewOperationTypeId == Expense ? Model.GetTransactionDifNew_Old : 0;

            if (Model.IsEditScore)
            {
                Model.OldScore.Balance -= Model.NewOperationTypeId == Income ? Model.GetTransactionDifNew_Old : 0;
                Model.OldScore.Balance += Model.NewOperationTypeId == Expense ? Model.GetTransactionDifNew_Old : 0;

                if (Model.OldScore.Balance < 0)
                {
                    throw new TransactionException("Недостаточно средств на счете!");
                }
            }

            if (Model.NewScore.Balance < 0)
            {
                throw new TransactionException("Недостаточно средств на счете!");
            }
        }
Пример #4
0
 private async Task <(bool, string)> RedactAndCheckTransaction(TransactionEditHelperModel model)
 {
     try
     {
         var Handler = new TransactionOperationEditHanlder();
         Handler.HandleRequest(model);
         return(true, null);
     }
     catch (TransactionException e)
     {
         return(false, e.Message);
     }
 }
 public TransactionEditHelperModelBuilder()
 {
     Model = new TransactionEditHelperModel();
 }
Пример #6
0
 public abstract void HandleRequest(TransactionEditHelperModel Model);