Exemple #1
0
        public IActionResult SavingConfirmed(string id)
        {
            try
            {
                var deposit = _depositService.List().Single(x => x.DepositId == id);
                if (deposit != null)
                {
                    var lastCustomerTransaction          = _depositService.CustomerLastTransaction(deposit);
                    var lastCustomerConfirmedTransaction = _depositService.CustomerLastConfirmedTransaction(deposit);
                    switch (deposit.TransactionCode)
                    {
                    case TransactionCode.Deposit:
                        deposit.Balance = lastCustomerConfirmedTransaction.Balance + deposit.Amount;
                        break;

                    case TransactionCode.Withdrawal:
                        deposit.Balance = lastCustomerConfirmedTransaction.Balance - deposit.Amount;

                        break;
                    }

                    deposit.StatusCode = Data.Enums.StatusCode.Confirmed;
                    _depositService.Update(deposit);


                    _depositConfirmService.Create(new DepositConfirmModel()
                    {
                        DepositId  = id,
                        EmployeeId = GetEmployeeId().Result,
                        CustomerId = deposit.CustomerId
                    });

                    if (deposit.TransactionCode == TransactionCode.Withdrawal)
                    {
                        var withdrawalFee = Convert.ToInt32(_feeSettings.Withdrawal);
                        var balance       = deposit.Balance - withdrawalFee;
                        var feemodel      = new DepositModel
                        {
                            CustomerId      = deposit.CustomerId,
                            EmployeeId      = GetEmployeeId().Result,
                            ProductId       = deposit.ProductId,
                            TransactionCode = TransactionCode.Fee,
                            StatusCode      = Data.Enums.StatusCode.Confirmed,
                            Amount          = withdrawalFee,
                            Balance         = balance,
                            DateCreated     = DateTime.UtcNow,
                        };

                        _depositService.Create(feemodel);
                    }
                }

                return(RedirectToAction("Confirmation"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + " " + ex.InnerException);
            }
            return(Content("Internal server error please contact the system administrator"));
        }