public async Task <AccountLoan> Create(AccountLoan accountLoan)
        {
            _context.AccountLoans.Add(accountLoan);
            await _context.SaveChangesAsync();

            return(accountLoan);
        }
예제 #2
0
        public async Task <Account> Create(Account model)
        {
            _context.Accounts.Add(model);
            await _context.SaveChangesAsync();

            return(model);
        }
예제 #3
0
        public async Task <IActionResult> Put(CustomerDto customer)
        {
            // If the caller doesnt provide id we try getting it from claims
            customer.Id ??= User.Claims.FirstOrDefault(c => c.Type.Equals(JwtClaimTypes.Name))?.Value;

            if (customer.Id == null)
            {
                logger.LogDebug("No id provided or found for the User");
                return(BadRequest("No Id provided"));
            }

            var dbCustomer = await dbContext.Customers.FindAsync(customer.Id);

            if (dbCustomer == null)
            {
                logger.LogDebug($"No Customer found in db for id: {customer.Id}");
                return(NotFound("Customer not found"));
            }

            dbContext.Attach(dbCustomer);

            dbCustomer.RegistrationNumber = customer.RegistrationNumber;

            await dbContext.SaveChangesAsync();

            logger.LogDebug($"Customer updated with id: {customer.Id}");

            return(Ok(dbCustomer));
        }
예제 #4
0
        public async Task <CountersReport> Create(CountersReport countersReport)
        {
            _context.CountersReports.Add(countersReport);
            await _context.SaveChangesAsync();

            return(countersReport);
        }
예제 #5
0
        public async Task <bool> Create(Customer customer)
        {
            _context.Add(customer);
            await _context.SaveChangesAsync();

            return(true);
        }
예제 #6
0
        public async Task <ServiceResponse <AccountBalance> > AddAmount(AccountBalance accountBalance)
        {
            try
            {
                accountBalance.AccountBalanceId = 0; //Identity column
                //Adding data into transaction table to capture transaction history
                TransactionAudit audit = new TransactionAudit();
                audit.ActionId    = 1; // FirstTime Add Amount
                audit.CustomerId  = accountBalance.CustomerId;
                audit.Balance     = accountBalance.Balance;
                audit.CreatedDate = DateTime.Now;
                await _bankDbContext.TransactionAudits.AddAsync(audit);

                await _bankDbContext.AccountBalances.AddAsync(accountBalance);

                await _bankDbContext.SaveChangesAsync();

                serviceResponse.Data    = accountBalance;
                serviceResponse.Message = $"First time amount added successfully...Balance is {accountBalance.Balance}";
                return(serviceResponse);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
                return(serviceResponse);
            }
        }
        public async Task <IActionResult> Create(BillPay billPay)
        {
            if (ModelState.IsValid)
            {
                if (_context.Account.Where(x => x.AccountNumber == billPay.AccountNumber).FirstOrDefault().Balance > billPay.Amount && billPay.Amount > 0)
                {
                    if (billPay.ScheduleDate < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")))
                    {
                        ModelState.AddModelError(nameof(billPay.ScheduleDate), "Invaild data time.");
                    }
                    else
                    {
                        ViewData["ErrorMessage"] = "";
                        billPay.ModifyDate       = DateTime.UtcNow;
                        billPay.Status           = BillPayStatus.Available;
                        _context.Add(billPay);
                        await _context.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                else
                {
                    ModelState.AddModelError(nameof(billPay.Amount), "Not enough money or invaild amount.");
                }
            }

            ViewData["AccountNumber"] = new SelectList(_context.Account.Where(a => a.CustomerID == CustomerID), "AccountNumber", "AccountNumber");
            ViewData["PayeeID"]       = new SelectList(_context.Payee.Where(x => x.PayeeID > 0), "PayeeID", "PayeeName");
            return(View(billPay));
        }
        public async Task <LoginReport> Create(LoginReport loginReport)
        {
            _context.LoginReports.Add(loginReport);
            await _context.SaveChangesAsync();

            return(loginReport);
        }
        public async Task <UserInfo> Create(UserInfo model)
        {
            _context.UserInfos.Add(model);
            await _context.SaveChangesAsync();

            return(model);
        }
예제 #10
0
        public async Task <FiltersReport> Create(FiltersReport filtersReport)
        {
            _context.FiltersReports.Add(filtersReport);
            await _context.SaveChangesAsync();

            return(filtersReport);
        }
예제 #11
0
        public async Task <IActionResult> PutBank([FromRoute] int id, [FromBody] Bank bank)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bank.BankID)
            {
                return(BadRequest());
            }

            _context.Entry(bank).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BankExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #12
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <TransfersReport> Create(TransfersReport transfersReport)
        {
            _context.TransfersReports.Add(transfersReport);
            await _context.SaveChangesAsync();

            return(transfersReport);
        }
예제 #14
0
        public async Task <TransactionsHistory> Create(TransactionsHistory model)
        {
            _context.TransactionsHistories.Add(model);
            await _context.SaveChangesAsync();

            return(model);
        }
예제 #15
0
        public async Task <Loan> Create(Loan loan)
        {
            _context.Loans.Add(loan);
            await _context.SaveChangesAsync();

            return(loan);
        }
예제 #16
0
        public async Task <Card> Create(Card card)
        {
            _context.Cards.Add(card);
            await _context.SaveChangesAsync();

            return(card);
        }
        public async Task <AccountDeposit> Create(AccountDeposit accountDeposit)
        {
            _context.UserDeposits.Add(accountDeposit);
            await _context.SaveChangesAsync();

            return(accountDeposit);
        }
예제 #18
0
        public async Task <IActionResult> Create([Bind("AccountNumber,Name,DOB,PhoneNo,Address,City,ZipCode,State,OpeningDate,Balance")] Account _account)
        {
            if (ModelState.IsValid)
            {
                _context.Add(_account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(_account));
        }
예제 #19
0
        public async Task <IActionResult> Create([Bind("Id,firstName,lastName,email,phoneNumber,address")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
예제 #20
0
        public async Task <IActionResult> Create([Bind("Id,type,accountNumber,CustomerId,InterestRate,Balance,createdAt,status,period,dateAndTime")] Saving saving)
        {
            if (ModelState.IsValid)
            {
                _context.Add(saving);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Id", saving.CustomerId);
            return(View(saving));
        }
예제 #21
0
        public async Task <IActionResult> Create([Bind("Maturity,Id,OwnerId,type,Amount")] TermDepositAccount termDepositAccount)
        {
            termDepositAccount.type    = Account.Types.TermDeposit;
            termDepositAccount.OwnerId = _userManager.GetUserId(User);
            if (ModelState.IsValid)
            {
                _context.Add(termDepositAccount);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(termDepositAccount));
        }
예제 #22
0
        public async Task <IActionResult> Create([Bind("Overdraft,OverdraftCost,OverdraftDueDate,Id,OwnerId,type,Amount")] BusinessAccount businessAccount)
        {
            businessAccount.type    = Account.Types.Business;
            businessAccount.OwnerId = _userManager.GetUserId(User);
            if (ModelState.IsValid)
            {
                _context.Add(businessAccount);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(businessAccount));
        }
        public async Task <IActionResult> Create([Bind("Id,OwnerId,type,Amount")] Account account)
        {
            account.type    = Account.Types.Checking;
            account.OwnerId = _userManager.GetUserId(User);
            if (ModelState.IsValid)
            {
                _context.Add(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
예제 #24
0
        public async Task <IActionResult> Create([Bind("MonthlyDue,Id,OwnerId,type,Amount")] LoanAccount loanAccount)
        {
            loanAccount.type       = Account.Types.Loan;
            loanAccount.OwnerId    = _userManager.GetUserId(User);
            loanAccount.MonthlyDue = loanAccount.Amount / 24;
            if (ModelState.IsValid)
            {
                _context.Add(loanAccount);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(loanAccount));
        }
예제 #25
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Address,UserRef,Age")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                var user = await _context.Users.FirstOrDefaultAsync(m => m.UserName == HttpContext.User.Identity.Name);

                customer.UserRef = user.Id;
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserRef"] = new SelectList(_context.Set <User>(), "Id", "Id", customer.UserRef);
            return(View(customer));
        }
        public async Task <Card> ApproveCard(int id, Card card)
        {
            var getCard = await GetById(id);

            getCard.Status     = CardStatus.Active.ToString();
            getCard.ExpireDate = card.ExpireDate;
            getCard.CCV        = card.CCV;
            getCard.CardNumber = card.CardNumber;
            getCard.CreatedAt  = DateTime.Now;
            await Update(getCard);

            await _context.SaveChangesAsync();

            return(card);
        }
예제 #27
0
        public async Task <IActionResult> Deposits(float amount)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User); //Current logged user

            var natural = await GetNaturalAsync(user.Id);

            if (natural != null)
            {
                natural.SavingAccounts[DefaultAccount].Amount += amount;
                var depositCertificate = new DepositCertificate
                {
                    Amount          = amount,
                    Balance         = natural.SavingAccounts[DefaultAccount].Amount,
                    Currency        = "US Dollar",
                    DateHour        = DateTime.Now.ToString("f"),
                    SavingAccountId = natural.SavingAccounts[DefaultAccount].Id
                };
                await _dbContext.DepositCertificates.AddAsync(depositCertificate);

                await _dbContext.SaveChangesAsync();

                return(View("Natural", natural));
//                return LocalRedirect(returnUrl);
            }

            var juridic = await GetJuridicAsync(user.Id);

            if (juridic != null)
            {
                juridic.SavingAccounts[DefaultAccount].Amount += amount;
                var depositCertificate = new DepositCertificate
                {
                    Amount          = amount,
                    Balance         = juridic.SavingAccounts[DefaultAccount].Amount,
                    Currency        = "US Dollar",
                    DateHour        = DateTime.Now.ToString("f"),
                    SavingAccountId = juridic.SavingAccounts[DefaultAccount].Id
                };
                await _dbContext.DepositCertificates.AddAsync(depositCertificate);

                await _dbContext.SaveChangesAsync();

                return(View("Juridic", juridic));
//                    return LocalRedirect(returnUrl);
            }

            return(NotFound());
        }
예제 #28
0
        public async Task <ActionResult> Create(Transfer transfer, CancellationToken cancellationToken = default)
        {
            var fromBankAccount = await _dbContext.BankAccounts.FindAsync(transfer.FromBankAccountId);

            var toBankAccount = await _dbContext.BankAccounts.FindAsync(transfer.ToBankAccountId);

            if (fromBankAccount == null)
            {
                return(BadRequest($"Bank account does not exist {transfer.FromBankAccountId}"));
            }

            if (toBankAccount == null)
            {
                return(BadRequest($"Bank account does not exist {transfer.ToBankAccountId}"));
            }

            if (fromBankAccount.HasFunds(transfer.Amount))
            {
                await _dbContext.Transfers.AddAsync(transfer, cancellationToken);

                fromBankAccount.WithdrawFunds(transfer.Amount);
                toBankAccount.DepositFunds(transfer.Amount);

                await _dbContext.SaveChangesAsync(cancellationToken);
            }
            else
            {
                return(BadRequest("Insufficient funds"));
            }

            return(CreatedAtAction(nameof(Get), new { id = transfer.Id }, transfer));
        }
예제 #29
0
        public async Task <string> Get1()
        {
            var dbconnect = _aplloDbContext.Database.GetDbConnection();


            BankDbContext bankDb = new BankDbContext(new DbContextOptionsBuilder <BankDbContext>().UseNpgsql(dbconnect).Options);


            using (var transcation = await _aplloDbContext.Database.BeginTransactionAsync())
            {
                await _aplloDbContext.AddAsync(new TestApllo { Name = "2222撒大声地" });

                await _aplloDbContext.SaveChangesAsync();

                bankDb.Database.UseTransaction(transcation.GetDbTransaction());

                await bankDb.AddAsync(new TestBank { Name = "444444sdsd" });

                await bankDb.SaveChangesAsync();

                await transcation.CommitAsync();
            }

            return("2");
        }
예제 #30
0
        protected override Task Handle(CalculateIncomeCommand request, CancellationToken cancellationToken)
        {
            var accounts = this._context.Accounts.ToArray();

            _yieldService.CalculateInterestFor(request.ForDate, accounts, request.InterestRate, cancellationToken, days: 1);
            _context.SaveChangesAsync(cancellationToken);
            return(Task.CompletedTask);
        }