Example #1
0
        public IActionResult PayAbilityCheck(string accountNumber, string amount)
        {
            var account = _accountRepository.Get(accountNumber);
            var result  = _currencyService.CheckBalanceToPay(account, Convert.ToDecimal(amount));

            return(Json(result));
        }
Example #2
0
        public string UpdateAmountResult(long id, decimal amount)
        {
            var myReg = new Regex(@"[\d]*[.,][\d]{1,2}|[\d]*"); //излишне?

            var isMatch = myReg.IsMatch(amount.ToString());

            string result;

            if (!isMatch)
            {
                result = "wrong amount";
                return(JsonConvert.SerializeObject(result));
            }

            var account = _bankAccountRepository?.Get(id);

            if (account == null || account.IsFrozen)
            {
                result = "wrong account";
                return(JsonConvert.SerializeObject(result));
            }
            if (amount < 0)
            {
                result = _transactionService.Withdrawal(account, amount);
            }
            else
            {
                result = _transactionService.Deposit(account, amount);
            }

            return(result);
        }
 public override void Project(IEvent @event, long eventNumber)
 {
     if (@event is BankAccountCreated bankAccountCreated)
     {
         var newBankAccount = bankAccountCreated.ToReadModel();
         bankAccountRepository.Create(newBankAccount);
     }
     else if (@event is AmountDeposited amountDeposited)
     {
         var bankAccount = bankAccountRepository.Get(amountDeposited.BankAccountId);
         var transaction = amountDeposited.ToReadModel(bankAccount.AccountNo);
         amountDeposited.Map(bankAccount);
         bankAccountRepository.Update(bankAccount);
         bankAccountRepository.Create(transaction);
     }
     else if (@event is AmountWithdrawn amountWithdrawn)
     {
         var bankAccount = bankAccountRepository.Get(amountWithdrawn.BankAccountId);
         var transaction = amountWithdrawn.ToReadModel(bankAccount.AccountNo);
         amountWithdrawn.Map(bankAccount);
         bankAccountRepository.Update(bankAccount);
         bankAccountRepository.Create(transaction);
     }
     else if (@event is BankAccountClosed bankAccountClosed)
     {
         var bankAccount = bankAccountRepository.Get(bankAccountClosed.Id);
         bankAccountClosed.Map(bankAccount);
         bankAccountRepository.Update(bankAccount);
     }
     bankAccountRepository.UpdateEventNumber(eventNumber);
 }
Example #4
0
        public void Transfer(long fromAccountId,
                             long toAccountId,
                             decimal transferAmount)
        {
            var transferCurrency = _bankAccountRepository
                                   .Get(fromAccountId)
                                   .Currency;

            Transfer(fromAccountId, toAccountId, transferAmount, transferCurrency);
        }
Example #5
0
        public GrapQlQuery(IBankAccountRepository bankAccountRepository, IBankRepository bankRepository)
        {
            Field <ListGraphType <BankAccountType> >(
                "bankAccounts",
                resolve: context => bankAccountRepository.Get()
                );
            Field <ListGraphType <BankType> >(
                "banks",
                resolve: context => bankRepository.Get()
                );

            Field <BankAccountType>(
                name: "bankAccountGetById",
                arguments: new QueryArguments(new
                                              QueryArgument <StringGraphType>
            {
                Name = "id"
            }),
                resolve: context =>
            {
                Guid id = context.GetArgument <Guid>("id");
                return(bankAccountRepository.GetById(id));
            }
                );
        }
Example #6
0
        public BankAccountDTO UpdateBankAccount(BankAccountDTO bankAccountDTO)
        {
            if (bankAccountDTO == null || bankAccountDTO.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotAddNullBankAccountOrInvalidCustomer));
            }

            //check if exists the customer for this bank account
            var associatedBankAccount = _bankAccountRepository.Get(bankAccountDTO.Id);
            var associatedCustomer    = _customerRepository.Get(bankAccountDTO.CustomerId);

            if (associatedBankAccount != null) // if the customer exist
            {
                associatedCustomer.FirstName = bankAccountDTO.CustomerFirstName;
                associatedCustomer.LastName  = bankAccountDTO.CustomerLastName;
                //save bank account
                SaveBankAccount(associatedBankAccount, associatedCustomer);

                return(associatedBankAccount.ProjectedAs <BankAccountDTO>());
            }
            else //the customer for this bank account not exist, cannot create a new bank account
            {
                throw new InvalidOperationException(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotCreateBankAccountForNonExistingCustomer));
            }
        }
 public IEnumerable <BankAccount> Get(Expression <Func <BankAccount, bool> > filter = null, string includeProperties = null)
 {
     try
     {
         return(_bankRepository.Get(filter, includeProperties: includeProperties));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #8
0
        public bool LockBankAccount(Guid bankAccountId)
        {
            //recover bank account, lock and commit changes
            var bankAccount = _bankAccountRepository.Get(bankAccountId);

            if (bankAccount != null)
            {
                bankAccount.Lock();

                _bankAccountRepository.UnitOfWork.Commit();

                return(true);
            }
            else // if not exist the bank account return false
            {
                _logger.LogWarning(_resources.GetStringResource(LocalizationKeys.Application.warning_CannotLockNonExistingBankAccount), bankAccountId);

                return(false);
            }
        }
 public ActionResult <List <BankAccount> > Get([FromServices] IBankAccountRepository repository)
 {
     try
     {
         return(Ok(repository.Get().AsNoTracking().ToList()));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex));
     }
 }
        /// <summary>
        /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IBankAppService"/>
        /// </summary>
        /// <param name="bankAccountId"><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IBankAppService"/></param>
        /// <returns><see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IBankAppService"/></returns>
        public bool LockBankAccount(Guid bankAccountId)
        {
            //recover bank account, lock and commit changes
            var bankAccount = _bankAccountRepository.Get(bankAccountId);

            if (bankAccount != null)
            {
                bankAccount.Lock();

                _bankAccountRepository.UnitOfWork.Commit();

                return(true);
            }
            else // if not exist the bank account return false
            {
                LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotLockNonExistingBankAccount, bankAccountId);

                return(false);
            }
        }
Example #11
0
        public decimal getBalance(Guid userId)
        {
            var bankAccount = _bankAccountRepository.Get()
                              .Where(b => b.UserId == userId)
                              .FirstOrDefault();

            if (bankAccount == null)
            {
                throw new TransferServiceException(TransferServiceException.Error.NotFound);
            }

            return(bankAccount.Balance);
        }
Example #12
0
        public IEnumerable <BankAccountDTO> ViewAccounts(Guid owner)
        {
            var customer = _customerLogic.ViewCustomer(owner);

            if (customer == null)
            {
                return(null);
            }

            var accounts = _repository.Get(filter: c => c.OwnerId == customer.Id);

            return(_dtoMapper.MapAll(accounts));
        }
 public IActionResult Get([FromServices] IBankAccountRepository repository, int id)
 {
     try
     {
         BankAccount BankAccount = repository.Get().Include(x => x.Transactions).AsNoTracking().FirstOrDefault(x => x.Id == id);
         if (User == null)
         {
             return(NotFound(new { message = "Conta inválida" }));
         }
         return(Ok(User));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex));
     }
 }
 public ActionResult <BankAccount> Delete(
     [FromServices] IBankAccountRepository repository, int id)
 {
     try
     {
         BankAccount ca = repository.Get().AsNoTracking().FirstOrDefault(x => x.Id == id);
         if (User == null)
         {
             return(NotFound(new { message = "Conta inválida" }));
         }
         repository.Delete(ca);
         return(Ok(new { message = "Conta excluida" }));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, ex));
     }
 }
Example #15
0
 public async Task <BankAccountModel> Get(int id)
 {
     return(await _bankAccountRepository.Get(id));
 }
Example #16
0
        public async Task <IActionResult> GetBankAccount(int idBankAccount)
        {
            var bankAccount = await _bankAccountRepository.Get(idBankAccount);

            return(Ok(bankAccount));
        }
        public IActionResult DownloadLog(long id)
        {
            var    webPath    = _hostEnvironment.WebRootPath;
            var    folderPath = Path.Combine(webPath, "TempFile");
            var    user       = _userService.GetCurrent();
            var    path       = Path.Combine(webPath, "TempFile", $"{user.Id}.docx");
            var    account    = _bankAccountRepository.Get(id);
            var    countRows  = 6;
            Border slimLine   = new Border(BorderStyle.Tcbs_single, BorderSize.one, 0, Color.Black);
            Border boldLine   = new Border(BorderStyle.Tcbs_single, BorderSize.seven, 0, Color.Black);

            if (!System.IO.Directory.Exists(folderPath))
            {
                System.IO.Directory.CreateDirectory(folderPath);
            }

            using (var doc = DocX.Create(path))
            {
                doc.InsertParagraph($"Детали счета \"{account.Name}\":")
                .Font("Comic Sans MS")
                .Bold()
                .FontSize(25)
                .Alignment = Alignment.center;
                doc.InsertParagraph("");

                var table = doc.InsertTable(countRows, 2);

                table.Rows[0].Cells[0].Paragraphs.First().Append("Account name").Bold().FontSize(14).Italic();
                table.Rows[1].Cells[0].Paragraphs.First().Append("Currency").Bold().FontSize(14).Italic();
                table.Rows[2].Cells[0].Paragraphs.First().Append("Amount").Bold().FontSize(14).Italic();
                table.Rows[3].Cells[0].Paragraphs.First().Append("Account number").Bold().FontSize(14).Italic();
                table.Rows[4].Cells[0].Paragraphs.First().Append("Creation date").Bold().FontSize(14).Italic();
                table.Rows[5].Cells[0].Paragraphs.First().Append("Expiry date").Bold().FontSize(14).Italic();

                table.Rows[0].Cells[1].Paragraphs.First().Append(account.Name).FontSize(12).Alignment = Alignment.center;
                table.Rows[1].Cells[1].Paragraphs.First().Append(account.Currency.ToString()).FontSize(12).Alignment     = Alignment.center;
                table.Rows[2].Cells[1].Paragraphs.First().Append(account.Amount.ToString()).FontSize(12).Alignment       = Alignment.center;
                table.Rows[3].Cells[1].Paragraphs.First().Append(account.AccountNumber).FontSize(12).Alignment           = Alignment.center;
                table.Rows[4].Cells[1].Paragraphs.First().Append(account.CreationDate.ToString()).FontSize(12).Alignment = Alignment.center;
                table.Rows[5].Cells[1].Paragraphs.First().Append(account.ExpireDate.ToString()).FontSize(12).Alignment   = Alignment.center;

                for (int i = 0; i < countRows; i++)
                {
                    table.Rows[i].Cells[0].FillColor = Color.LightGreen;
                }

                table.SetBorder(TableBorderType.InsideH, slimLine);
                table.SetBorder(TableBorderType.InsideV, slimLine);
                table.SetBorder(TableBorderType.Bottom, boldLine);
                table.SetBorder(TableBorderType.Top, boldLine);
                table.SetBorder(TableBorderType.Left, boldLine);
                table.SetBorder(TableBorderType.Right, boldLine);

                table.Alignment = Alignment.center;

                doc.Save();
            }

            var contentTypeDocx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            var fileName        = $"Info about '{account.Name}' account.docx";

            return(PhysicalFile(path, contentTypeDocx, fileName));
        }
Example #18
0
 public IQueryable <BankAccountDmo> Get()
 {
     return(_bankAccountRepository.Get());
 }