public async Task <IActionResult> Withdraw(int?id, double withdraw)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var account = await _context.Accounts.FindAsync(id);

            if (account.Amount - withdraw >= 0)
            {
                account.Amount = account.Amount - withdraw;
            }

            try
            {
                _context.Update(account);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountExists(account.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 2
0
        public async Task <IActionResult> Deposit(int?id, double deposit)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var account = await _context.LoanAccounts.FindAsync(id);

            if (deposit > account.MonthlyDue)
            {
                account.Amount = account.Amount - deposit;
            }



            try
            {
                _context.Update(account);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccountExists(account.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(int id, [Bind("AccountNumber,Name,DOB,PhoneNo,Address,City,ZipCode,State,OpeningDate,Balance")] Account _account)
        {
            if (id != _account.AccountNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(_account);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(_account.AccountNumber))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(_account));
        }
        public async Task <IActionResult> Modify(int id, decimal amount, DateTime scheduleDate, Period period)
        {
            var billPay = _context.BillPay.Find(id);

            if (id != billPay.BillPayID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    billPay.Amount       = amount;
                    billPay.ScheduleDate = scheduleDate;
                    billPay.Period       = period;

                    _context.Update(billPay);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _context.BillPay.AnyAsync(x => x.BillPayID == billPay.BillPayID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(billPay));
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,type,accountNumber,CustomerId,InterestRate,Balance,createdAt,status,period,dateAndTime")] Saving saving)
        {
            if (id != saving.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(saving);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SavingExists(saving.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "Id", "Id", saving.CustomerId);
            return(View(saving));
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Address,UserRef,Age")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserRef"] = new SelectList(_context.Set <User>(), "Id", "Id", customer.UserRef);
            return(View(customer));
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,firstName,lastName,email,phoneNumber,address")] Customer customer)
        {
            if (id != customer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(customer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
Esempio n. 8
0
        public async Task <bool> Edit(int id, Customer customer)
        {
            _context.Update(customer);
            await _context.SaveChangesAsync();

            return(true);
        }
Esempio n. 9
0
        public T Update(T itemToUpdate)
        {
            var entity = dbContext.Update <T>(itemToUpdate);

            dbContext.SaveChanges();
            return(entity.Entity);
        }
Esempio n. 10
0
        public async Task <IActionResult> Deposit(int id, [Bind("TranId,amount,date,TranscationType, account")] Transaction transaction)
        {
            var account = _context.Accounts.FirstOrDefault(m => m.AccountNumber == id);

            //account.Balance += transaction.amount;
            transaction.account         = account;
            transaction.date            = DateTime.Now;
            transaction.TranscationType = "Deposit";
            if (ModelState.IsValid && account.Deposit(transaction.amount) && account.IsActive)
            {
                _context.Add(transaction);
                _context.Update(account);
                await _context.SaveChangesAsync();

                return(RedirectToAction("../Accounts/Index"));
            }
            ViewBagInfo(id);
            ViewBag.ErrorMessage = "Invalid operation! Check the amount or your account status.";
            return(View(transaction));
        }
Esempio n. 11
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var account = await _context.Accounts.FindAsync(id);

            //_context.Accounts.Remove(account);
            account.IsActive = false;
            _context.Update(account);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 12
0
        public async Task <IActionResult> Withdraw(int?id, double withdraw)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var account = await _context.BusinessAccounts.FindAsync(id);

            if (account.Overdraft == 0)
            {
                account.Amount = account.Amount - withdraw;
            }
            if (account.Amount < 0)
            {
                DateTime today = DateTime.Today;
                account.Overdraft        = Math.Abs(account.Amount);
                account.Amount           = 0;
                account.OverdraftCost    = account.Overdraft * .08 + account.Overdraft;
                account.OverdraftDueDate = 30;
            }

            try
            {
                _context.Update(account);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BusinessAccountExists(account.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }