public ActionResult CreateBankUser([Bind("Id,AccountNumber, AccountName,ContactNo, Balance")] BankUserDTO bankuser)
        {
            try
            {
                BankUser newBankUser = new BankUser();

                if (bankuser != null)
                {
                    newBankUser = new BankUser
                    {
                        Id            = bankuser.Id,
                        AccountName   = bankuser.AccountName,
                        AccountNumber = bankuser.AccountNumber,
                        ContactNo     = bankuser.ContactNo,
                        Balance       = bankuser.Balance,
                        EntityState   = EntityState.Added
                    };
                    _businessLayer.AddBankUser(newBankUser);
                }
                return(Ok(newBankUser));
            }

            catch (Exception ex)
            {
                //return new JsonResult(new { HttpStatusCode = NotFound(HttpStatusCode.BadRequest), ex.Message });
                throw new Exception(ex.Message);
            }
        }
예제 #2
0
        public async Task <bool> CreateBankUsers(BankUserDTO bankUserDTO)
        {
            //User user
            //Check if username exist
            var isUserExist = await _userService.GetBy(f => f.Username == bankUserDTO.UserName);

            if (isUserExist?.Id > 0)
            {
                throw new Exception("Username Already exist");
            }
            Person person = new Person()
            {
                //mapping user entered field to the database table
                AccountNo      = bankUserDTO.AccountNo,
                Account_TypeId = bankUserDTO.Account_Type_Id,
                Firstname      = bankUserDTO.FirstName,
                Lastname       = bankUserDTO.LastName,
                IsActive       = true,
                PhoneNo        = bankUserDTO.PhoneNo
            };
            var personCreated = await _personService.Save(person);

            if (personCreated > 0)
            {
                User user = new User()
                {
                    Password = bankUserDTO.Password,
                    PersonId = person.Id,
                    Username = bankUserDTO.UserName
                };
                var userCreated = await _userService.Save(user);

                if (userCreated > 0)
                {
                    Bank_Activity bank_Activity = new Bank_Activity()
                    {
                        Balance          = bankUserDTO.InitialDeposit,
                        Description      = "Opening account deposit",
                        IsDeposit        = true,
                        IsOpeningBalance = true,
                        PersonId         = person.Id,
                        TrasactionAmount = bankUserDTO.InitialDeposit,
                        TransactionDate  = DateTime.Now
                    };
                    var created = await _bankActivityService.Save(bank_Activity);

                    if (created > 0)
                    {
                        Last_Transaction last_Transaction = new Last_Transaction()
                        {
                            Balance     = bankUserDTO.InitialDeposit,
                            DateCreated = DateTime.Now,
                            PersonId    = person.Id
                        };
                        await _lastTransactionService.Save(last_Transaction);
                    }
                    return(true);
                }
            }
            return(false);
        }
        public async Task <IActionResult> CreateNewAccount(BankUserDTO bankUserDTO)
        {
            var response = await _accountService.CreateBankUsers(bankUserDTO);

            return(Ok(response));
        }