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);
 }
Пример #2
0
        public ICommandResult Handle(CreateBankAccountCommand command)
        {
            command.Validate();

            if (!command.Valid)
            {
                return(new BankAccountCommandResult(false, "Não foi possivel criar uma conta", command.Notifications));
            }


            var bankAccount = new BankAccount(
                command.BankName,
                command.Agency,
                command.AccountNumber);

            AddNotifications(bankAccount);


            if (Invalid)
            {
                return(new BankAccountCommandResult(false, "Não foi possivel criar uma conta", command.Notifications));
            }

            _bankAccountRepository.Create(bankAccount);

            return(new BankAccountCommandResult(true, "Conta criada com sucesso", command.Notifications));
        }
        public void CreateAccount(AccountType accountType, int accountNumber, Client Owner, Decimal balance, int bonusPoints)
        {
            BankAccount account = null;

            switch (accountType)
            {
            case AccountType.BaseAccount:
                account = factory.CreateBaseBankAccount(accountNumber, Owner, balance, bonusPoints);
                break;

            case AccountType.GoldAccount:
                account = factory.CreateGoldBankAccount(accountNumber, Owner, balance, bonusPoints);
                break;

            case AccountType.SilverAccount:
                account = factory.CreateSilverBankAccount(accountNumber, Owner, balance, bonusPoints);
                break;

            case AccountType.PlatinumAccount:
                account = factory.CreatePlatinumBankAccount(accountNumber, Owner, balance, bonusPoints);
                break;

            default:
                throw new ArgumentException($"AccountType:{accountType} doesn't exist");
            }

            try
            {
                repository.Create(account);
            }
            catch (Exception ex)
            {
                throw new DALException($"The error occured when creating the account", ex);
            }
        }
Пример #4
0
        public ICommandResults Handle(CreateAccountCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new CommandResults(false, "Ops, não foi possível cadastrar seu registro.", command.Notifications));
            }
            //var acc = _bankAccountRepository.GetById(command.Id);


            var bank          = _bankRepository.GetById(command.BankId);
            var accountCreate = new BankAccount(
                command.AccountType,
                bank.Id,
                command.Agency);

            // var acc = _bankAccountRepository.GetById(accountCreate.Id);


            if (_bankAccountRepository.AccountExists(accountCreate.Id))
            {
                return(new CommandResults(false, "Não é possível realizar o cadastro!", command));
            }

            AddNotifications(accountCreate.Notifications);
            if (Invalid)
            {
                return(new CommandResults(false, "Não foi possível realizar o cadastro de conta nova!!", command.Notifications));
            }
            _bankAccountRepository.Create(accountCreate);
            _bankAccountRepository.Save();

            return(new CommandResults(true, "Conta registrada com sucesso!!!", accountCreate));
        }
Пример #5
0
        public async Task <IActionResult> CreateBankAccount([FromBody] BankAccount bankAccount)
        {
            if (await _bankAccountRepository.Create(bankAccount))
            {
                return(Ok());
            }

            return(BadRequest());
        }
        public void CreateBankAccount(AccountDetails accountDetails, string userId)
        {
            var account = Mapper.Map <Account>(accountDetails);

            account.User_Id        = userId;
            account.CurrentBalance = account.InitialBalance;
            account.IsFavorite     = !_bankAccountRepository.GetList().Any(x => x.User_Id == userId);

            _bankAccountRepository.Create(account);
        }
Пример #7
0
        public ActionResult Create(BankAccountViewModel bankAccountVM)
        {
            if (ModelState.IsValid)
            {
                _bankAccountRepository.Create(bankAccountVM.BankAccount);
                _bankAccountLogic.CalculateBalanceOfAllAccounts();
                return(RedirectToAction("Index"));
            }

            return(View(bankAccountVM));
        }
        public ActionResult Create([Bind(Include = "acc_id,userid,iban,balance")] BankAccount bankAccount)
        {
            if (ModelState.IsValid)
            {
                bankAccountRepository.Create(bankAccount);
                //db.BankAccounts.Add(bankAccount);
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bankAccount));
        }
Пример #9
0
        public async Task <BankAccount> CreateAccount(IUser user)
        {
            var account = new BankAccount
            {
                UserId   = user.Id,
                Username = user.Username,
                Balance  = _options.StartingBalance < 0.01M
                    ? 0.00M
                    : _options.StartingBalance
            };

            var newAccount = await _bankAccountRepository.Create(account);

            return(newAccount);
        }
        public IActionResult Create(long customerId, [FromBody] BankAccountCreateDto bankAccountCreateDto)
        {
            //LoggerBasSingleton.Instance.Log("Inicio de función");
            //LoggerThreadSafe1Singleton.Instance.Log("Inicio de función");
            //LoggerThreadSafe2Singleton.Instance.Log("Inicio de función");
            //LoggerThreadSafe3Singleton.Instance.Log("Inicio de función");
            LoggerThreadSafe4LazySingleton.Instance.Log("Inicio de función");

            bankAccountCreateDto.CustomerId = customerId;
            BankAccount bankAccount = _bankAccountCreateAssembler.toEntity(bankAccountCreateDto);

            _bankAccountRepository.Create(bankAccount);

            LoggerThreadSafe4LazySingleton.Instance.Log("Fin de función");

            return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto("BankAccount Created!")));
        }
Пример #11
0
        public IActionResult Create(long customerId, [FromBody] BankAccountCreateDto bankAccountCreateDto)
        {
            bool uowStatus = false;

            try
            {
                uowStatus = _unitOfWork.BeginTransaction();
                bankAccountCreateDto.CustomerId = customerId;
                //TODO: Validations with Notification Pattern
                BankAccount bankAccount = _bankAccountCreateAssembler.toEntity(bankAccountCreateDto);
                _bankAccountRepository.Create(bankAccount);
                _unitOfWork.Commit(uowStatus);
                return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto("BankAccount Created!")));
            } catch (Exception ex) {
                _unitOfWork.Rollback(uowStatus);
                Console.WriteLine(ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, new ApiStringResponseDto("Internal Server Error")));
            }
        }
Пример #12
0
 public static BankAccount CreateNewBankAccount(IBankAccountRepository bankAccountRepo, BankAccount bankAccount)
 {
     return(bankAccountRepo.GetById(
                bankAccountRepo.Create(bankAccount)));
 }
Пример #13
0
 public async Task <int> Create(BankAccountForm form)
 {
     form.UserId = UserContext.UserId;
     return(await _bankAccountRepository.Create(form));
 }
        public BankAccount CreateAccount(double intrestRate, double actualBalance)
        {
            var newBankAcc = newBankAccount(intrestRate, actualBalance);

            return(_repo.Create(newBankAcc));
        }