Пример #1
0
 public ActionResult MakePayment([Bind(Include = "LoanId,Amount,CustomerId,Active")] Loan loan)
 {
     if (ModelState.IsValid)
     {
         double paymentAmount = loan.Amount;
         loan.Amount = (double)TempData["Amount"];
         if (paymentAmount > loan.Amount)
         {
             return(RedirectToAction("Index", new { id = loan.CustomerId }));
         }
         else if (paymentAmount < loan.Amount)
         {
             loan.Amount         -= paymentAmount;
             db.Entry(loan).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index", new { id = loan.CustomerId }));
         }
         else if (paymentAmount == loan.Amount)
         {
             loan.Amount          = 0;
             loan.Active          = false;
             db.Entry(loan).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("Index", new { id = loan.CustomerId }));
         }
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", loan.CustomerId);
     return(View(loan.CustomerId));
 }
Пример #2
0
        public ActionResult Withdraw(CheckingAccount checkingAccount)
        {
            if (ModelState.IsValid)
            {
                CheckingTransactionsController c = new CheckingTransactionsController();
                CheckingTransaction            transaction;

                var withdrawAmount = checkingAccount.Balance;
                checkingAccount.Balance = (double)TempData["CheckingBalance"];
                if (withdrawAmount > checkingAccount.Balance)
                {
                    return(RedirectToAction("WithdrawDenied", new { id = checkingAccount.CustomerId }));
                }
                else
                {
                    checkingAccount.Balance -= withdrawAmount;
                    transaction              = c.CreateTransaction(checkingAccount.CustomerId, checkingAccount.Id, withdrawAmount, "Withdraw");
                    db.CheckingTransaction.Add(transaction);
                    db.Entry(checkingAccount).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = checkingAccount.CustomerId }));
                }
            }

            ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", checkingAccount.CustomerId);
            return(RedirectToAction("Index", new { id = checkingAccount.CustomerId }));
        }
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Пример #4
0
        public IActionResult PayeeUpdate(Benficiarys ben)
        {
            if (string.IsNullOrEmpty(ben.Payee_Name))
            {
                ModelState.AddModelError("Payee Name", "Payee Name field is required");
            }
            if (string.IsNullOrEmpty(ben.Payee_Contact))
            {
                ModelState.AddModelError("contact", "contact field is required");
            }
            if (string.IsNullOrEmpty(ben.Bnak_name))
            {
                ModelState.AddModelError("Bankname", "Bank name field is required");
            }

            if (ModelState.IsValid)
            {
                var BenData = _db.Benficiarys.Where(x => x.ID == ben.ID).FirstOrDefault();
                if (BenData != null)
                {
                    BenData.Payee_Name       = ben.Payee_Name;
                    BenData.Bnak_name        = ben.Bnak_name;
                    BenData.Payee_Contact    = ben.Payee_Contact;
                    _db.Entry(BenData).State = EntityState.Modified;
                    _db.SaveChanges();
                    return(RedirectToAction("Payees", "Home"));
                }
            }
            return(View());
        }
 public IActionResult updateProfile(Registration re)
 {
     ViewBag.Message = "Profile Update";
     if (string.IsNullOrEmpty(re.Contact_No))
     {
         ModelState.AddModelError("Contact No", "Contact field is required");
     }
     if (string.IsNullOrEmpty(re.Email))
     {
         ModelState.AddModelError("Email", "Email field is required");
     }
     if (string.IsNullOrEmpty(re.Name))
     {
         ModelState.AddModelError("Name", "Name field is required");
     }
     if (string.IsNullOrEmpty(re.Password))
     {
         ModelState.AddModelError("Password", "Password field is required");
     }
     if (ModelState.IsValid)
     {
         var reData = _db.RegistrationTable.Where(x => x.ID == re.ID).FirstOrDefault();
         if (reData != null)
         {
             reData.Name             = re.Name;
             reData.Contact_No       = re.Contact_No;
             reData.Email            = re.Email;
             reData.Password         = re.Password;
             _db.Entry(reData).State = EntityState.Modified;
             _db.SaveChanges();
             return(RedirectToAction("Logout", "Registration"));
         }
     }
     return(View());
 }
Пример #6
0
 public ActionResult Edit([Bind(Include = "CustomerId,FirstName,LastName,Email,loanAmount")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Пример #7
0
 public ActionResult Edit([Bind(Include = "Id,AccountOneId,AccountTwoId")] Transfer transfer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(transfer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(transfer));
 }
Пример #8
0
 public ActionResult Edit([Bind(Include = "Id,AccountId,CustomerId,DateOfTransaction,Amount")] BusinessTransaction businessTransaction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(businessTransaction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(businessTransaction));
 }
 public ActionResult Edit([Bind(Include = "Id,AccountId,CustomerId,DateOfTransaction,Amount")] CheckingTransaction checkingTransaction)
 {
     if (ModelState.IsValid)
     {
         db.Entry(checkingTransaction).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AccountId  = new SelectList(db.CheckingAccounts, "Id", "Id", checkingTransaction.AccountId);
     ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", checkingTransaction.CustomerId);
     return(View(checkingTransaction));
 }
        public ActionResult Withdraw(BusinessAccount businessAccount)
        {
            if (ModelState.IsValid)
            {
                BusinessTransactionsController c = new BusinessTransactionsController();
                BusinessTransaction            transaction;

                double withDrawAmount = businessAccount.Balance;
                businessAccount.Balance = (double)TempData["AccountBalance"];
                double negativeAmount;
                if (businessAccount.Balance - withDrawAmount < -100)
                {
                    //ViewBag.WithdrawDenied = "You have attempted to withdraw over your limit";
                    return(RedirectToAction("WithdrawDenied", new { id = businessAccount.CustomerId }));
                }
                else if (businessAccount.Balance - withDrawAmount < 0)
                {
                    negativeAmount                  = businessAccount.Balance - withDrawAmount;
                    negativeAmount                 += negativeAmount * BusinessAccount.OverdraftFee;
                    businessAccount.Balance         = negativeAmount;
                    db.Entry(businessAccount).State = EntityState.Modified;
                    transaction = c.CreateTransaction(businessAccount.CustomerId, businessAccount.Id, -withDrawAmount, "Withdraw");
                    db.BusinessTransactions.Add(transaction);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = businessAccount.CustomerId }));
                }
                else
                {
                    businessAccount.Balance        -= withDrawAmount;
                    db.Entry(businessAccount).State = EntityState.Modified;
                    transaction = c.CreateTransaction(businessAccount.CustomerId, businessAccount.Id, withDrawAmount, "Withdraw");
                    db.BusinessTransactions.Add(transaction);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = businessAccount.CustomerId }));
                }
            }
            ViewBag.CustomerId = new SelectList(db.Customers, "Id", "FirstName", businessAccount.CustomerId);
            return(View(businessAccount.CustomerId));
        }
Пример #11
0
 public ActionResult Edit([Bind(Include = "Id,DateOpened,Amount,InterestRate")] TermDeposit termDeposit)
 {
     if (ModelState.IsValid)
     {
         db.Entry(termDeposit).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(termDeposit));
 }
Пример #12
0
        public void processRegisteredPayment(int id)
        {
            using (var db = new BankDBContext())
            {
                try
                {
                    DbRegisteredPayment payment         = db.RegisteredPayments.Find(id);
                    DbAccount           customerAccount = db.Accounts.FirstOrDefault(
                        a => a.accountNumber.Equals(payment.customerAccountNumber));
                    DbAccount targetAccount = db.Accounts.FirstOrDefault(
                        a => a.accountNumber.Equals(payment.targetAccountNumber));
                    DbIssuedPayment ip = new DbIssuedPayment()
                    {
                        customerAccountNumber = payment.customerAccountNumber,
                        targetAccountNumber   = payment.targetAccountNumber,
                        receiverName          = payment.receiverName,
                        amount     = payment.amount,
                        issuedDate = DateTime.Now,
                        customerAccountNumberFK = customerAccount
                    };
                    if (targetAccount != null)
                    {
                        ip.targetAccountNumberFK = targetAccount;
                    }
                    db.IssuedPayments.Add(ip);

                    DbRegisteredPayment test = db.RegisteredPayments.FirstOrDefault(rp => rp.id == payment.id);
                    db.RegisteredPayments.Remove(test);

                    customerAccount.balance        += payment.amount;
                    db.Entry(customerAccount).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    errorReport(e.ToString());
                    return;
                }
            }
        }
Пример #13
0
        public async Task <ActionResult> Edit(int?id, byte[] rowVersion)
        {
            string[] fieldsToBind = new string[] { "AccountNumber", "AccountName", "Password", "Balance", "CreatedDate", "RowVersion" };

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var accountToUpdate = await db.Accounts.FindAsync(id);

            if (accountToUpdate == null)
            {
                Account deletedAccount = new Account();
                TryUpdateModel(deletedAccount, fieldsToBind);
                ModelState.AddModelError(string.Empty,
                                         "Unable to save changes. The account was deleted by another user.");

                return(View(deletedAccount));
            }

            if (TryUpdateModel(accountToUpdate, fieldsToBind))
            {
                try
                {
                    db.Entry(accountToUpdate).OriginalValues["RowVersion"] = rowVersion;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    var entry         = ex.Entries.Single();
                    var clientValues  = (Account)entry.Entity;
                    var databaseEntry = entry.GetDatabaseValues();
                    if (databaseEntry == null)
                    {
                        ModelState.AddModelError(string.Empty,
                                                 "Unable to save changes. The account was deleted by another user.");
                    }
                    else
                    {
                        var databaseValues = (Account)databaseEntry.ToObject();

                        if (databaseValues.AccountNumber != clientValues.AccountNumber)
                        {
                            ModelState.AddModelError("AccountNumber", "Current value: "
                                                     + databaseValues.AccountNumber);
                        }
                        if (databaseValues.AccountName != clientValues.AccountName)
                        {
                            ModelState.AddModelError("AccountName", "Current value: "
                                                     + databaseValues.AccountName);
                        }
                        if (databaseValues.Password != clientValues.Password)
                        {
                            ModelState.AddModelError("Password", "Current value: "
                                                     + databaseValues.Password);
                        }
                        if (databaseValues.Balance != clientValues.Balance)
                        {
                            ModelState.AddModelError("Balance", "Current value: "
                                                     + String.Format("{0:c}", databaseValues.Balance));
                        }
                        if (databaseValues.CreatedDate != clientValues.CreatedDate)
                        {
                            ModelState.AddModelError("CreatedDate", "Current value: "
                                                     + String.Format("{0:d}", databaseValues.CreatedDate));
                        }

                        ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                                                 + "was modified by another user after you got the original value. The "
                                                 + "edit operation was canceled and the current values in the database "
                                                 + "have been displayed. If you still want to edit this record, click "
                                                 + "the Save button again. Otherwise click the Back to List hyperlink.");
                        accountToUpdate.RowVersion = databaseValues.RowVersion;
                    }
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }

            return(View(accountToUpdate));
        }