Example #1
0
 public ActionResult Edit([Bind(Include = "ID,Name,Address,SortCode,Status")] Branch branch)
 {
     if (ModelState.IsValid)
     {
         db.Entry(branch).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(branch));
 }
        public ActionResult Edit([Bind(Include = "ID,IsBusinessOpen,FinancialDate,SavingsCreditInterestRate,SavingsMinimumBalance,SavingsInterestExpenseGlID,SavingsInterestPayableGlID,CurrentCreditInterestRate,CurrentMinimumBalance,CurrentCot,CurrentInterestExpenseGlID,CurrentCotIncomeGlID,CurrentInterestPayableGlID,LoanDebitInterestRate,LoanInterestIncomeGlID,LoanInterestExpenseGLID,LoanInterestReceivableGlID")] AccountConfiguration accountConfiguration)
        {
            if (ModelState.IsValid)
            {
                if (accountConfiguration.SavingsInterestExpenseGlID == 0)
                {
                    accountConfiguration.SavingsInterestExpenseGlID = null;
                }
                if (accountConfiguration.SavingsInterestPayableGlID == 0)
                {
                    accountConfiguration.SavingsInterestPayableGlID = null;
                }
                if (accountConfiguration.CurrentCotIncomeGlID == 0)
                {
                    accountConfiguration.CurrentCotIncomeGlID = null;
                }
                if (accountConfiguration.CurrentInterestExpenseGlID == 0)
                {
                    accountConfiguration.CurrentInterestExpenseGlID = null;
                }
                if (accountConfiguration.CurrentInterestPayableGlID == 0)
                {
                    accountConfiguration.CurrentInterestPayableGlID = null;
                }
                if (accountConfiguration.LoanInterestExpenseGLID == 0)
                {
                    accountConfiguration.LoanInterestExpenseGLID = null;
                }
                if (accountConfiguration.LoanInterestIncomeGlID == 0)
                {
                    accountConfiguration.LoanInterestIncomeGlID = null;
                }
                if (accountConfiguration.LoanInterestReceivableGlID == 0)
                {
                    accountConfiguration.LoanInterestReceivableGlID = null;
                }

                db.Entry(accountConfiguration).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details"));
            }
            SetPostGlActViewBags(accountConfiguration);
            return(View(accountConfiguration));
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "ID,UserId,GlAccountID")] TillToUser tillToUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tillToUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //ViewBag.Users = new SelectList(UserManager.Users, "Id", "UserName", tillToUser.UserId);
     ViewBag.GlAccountID = new SelectList(db.GlAccounts, "ID", "AccountName", tillToUser.GlAccountID);
     return(View(tillToUser));
 }
Example #4
0
        public ActionResult Edit([Bind(Include = "ID,Name,Description,MainCategory")] GlCategory glCategory)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // original category is automatically being tracked by the db context. (because it was read from database, tracked with Unchanged status)
                    // its causing conflict when i track glCategory built by the model binder because they have the same primary key.
                    // my solution is to detach originalCategory from context tracking.

                    GlCategory originalCategory = db.GlCategories.Find(glCategory.ID);
                    db.Entry(originalCategory).State = EntityState.Detached;

                    string originalName = originalCategory.Name;
                    if (!glCategory.Name.ToLower().Equals(originalName.ToLower()))
                    {
                        if (!glCatLogic.IsUniqueName(glCategory.Name))
                        {
                            AddError("Please select another name");
                            return(View(glCategory));
                        }
                    }

                    db.Entry(glCategory).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(glCategory));
                }
            }
            AddError("Please enter valid data");
            return(View(glCategory));
        }
Example #5
0
        public ActionResult Edit([Bind(Include = "ID,AccountName,CodeNumber,AccountBalance,GlCategoryID,BranchID")] GlAccount glAccount)
        {
            ViewBag.BranchID = new SelectList(db.Branches, "ID", "Name", glAccount.BranchID);
            //ViewBag.GlCategoryID = new SelectList(db.GlCategories, "ID", "Name", glAccount.GlCategoryID);

            if (ModelState.IsValid)
            {
                try
                {
                    //it had to be detached because of the collision. the entity was being tracked by the context.
                    GlAccount originalAccount = db.GlAccounts.Find(glAccount.ID);
                    db.Entry(originalAccount).State = EntityState.Detached;

                    string originalName = originalAccount.AccountName;
                    if (!glAccount.AccountName.ToLower().Equals(originalName.ToLower()))
                    {
                        if (!glActLogic.IsUniqueName(glAccount.AccountName))
                        {
                            AddError("Please select another name");
                            return(View(glAccount));
                        }
                    }

                    db.Entry(glAccount).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(glAccount));
                }
            }
            AddError("Please enter valid data");
            return(View(glAccount));
        }
Example #6
0
        public ActionResult Edit([Bind(Include = "ID,CustId,FullName,Address,Email,PhoneNumber,Gender,Status")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    db.Entry(customer).State = EntityState.Modified;

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(customer));
                }
            }
            AddError("Please enter valid data");
            return(View(customer));
        }
Example #7
0
        public ActionResult CreateLoan([Bind(Include = "AccountName,LoanAmount,TermsOfLoan,NumberOfYears,InterestRate,BranchID,CustomerID,ServicingAccountNumber")] CreateLoanAccountViewModel model)
        {
            ViewBag.BranchID = new SelectList(db.Branches, "ID", "Name", model.BranchID);

            if (ModelState.IsValid)
            {
                try
                {
                    // general settings
                    CustomerAccount customerAccount = new CustomerAccount();
                    customerAccount.AccountName    = model.AccountName;
                    customerAccount.AccountType    = AccountType.Loan;
                    customerAccount.CustomerID     = model.CustomerID;
                    customerAccount.AccountNumber  = custActLogic.GenerateCustomerAccountNumber(AccountType.Loan, model.CustomerID);
                    customerAccount.DateCreated    = DateTime.Now;
                    customerAccount.BranchID       = model.BranchID;
                    customerAccount.AccountStatus  = AccountStatus.Closed;
                    customerAccount.AccountBalance = 0;

                    // loan specific settings
                    customerAccount.LoanAmount  = model.LoanAmount;
                    customerAccount.TermsOfLoan = model.TermsOfLoan;

                    long actNo = Convert.ToInt64(model.ServicingAccountNumber);

                    var servAct = db.CustomerAccounts.Where(a => a.AccountNumber == actNo).SingleOrDefault();
                    if (servAct == null)
                    {
                        AddError("Servicing account number does not exist");
                        return(View(model));
                    }
                    // check if servicing account number actually belongs to customer and is either savings or current.
                    if (servAct.AccountType == AccountType.Loan || servAct.CustomerID != model.CustomerID)
                    {
                        AddError("Invalid servicing account");
                        return(View(model));
                    }
                    // this checks if a Customer can get loans. it avoids creation of new accounts and taking loans
                    decimal loanEligible = 2000;
                    if (servAct.AccountBalance < loanEligible)
                    {
                        AddError("Service Account Balance Below Loan Eligible range");
                        return(View(model));
                    }
                    // checks if the customer account linked with loan is active
                    if (servAct.AccountStatus == AccountStatus.Closed)
                    {
                        AddError("Servicing account is closed");
                        return(View(model));
                    }

                    // get the id
                    customerAccount.ServicingAccountID = servAct.ID;

                    customerAccount.LoanInterestRatePerMonth = Convert.ToDecimal(model.InterestRate);
                    switch (model.TermsOfLoan)
                    {
                    case TermsOfLoan.Fixed:
                        custActLogic.ComputeFixedRepayment(customerAccount, model.NumberOfYears, model.InterestRate);
                        break;

                    case TermsOfLoan.Reducing:
                        custActLogic.ComputeReducingRepayment(customerAccount, model.NumberOfYears, model.InterestRate);
                        break;

                    default:
                        break;
                    }

                    // loan disbursement which happens after validations.
                    busLogic.DebitCustomerAccount(customerAccount, customerAccount.LoanAmount);
                    busLogic.CreditCustomerAccount(servAct, customerAccount.LoanAmount);

                    db.Entry(servAct).State = EntityState.Modified;
                    db.CustomerAccounts.Add(customerAccount);
                    db.SaveChanges();

                    // financial report logging
                    reportLogic.CreateTransaction(customerAccount, customerAccount.LoanAmount, TransactionType.Debit);
                    reportLogic.CreateTransaction(servAct, customerAccount.LoanAmount, TransactionType.Credit);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    AddError(ex.ToString());
                    return(View(model));
                }
            }
            AddError("Please enter valid data");
            return(View(model));
        }
Example #8
0
        public ActionResult Edit(EditRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Role role = db.Roles.Find(model.RoleId);
                    if (!model.Name.ToLower().Equals(role.Name.ToLower()))
                    {
                        if (roleLogic.isRoleNameExists(model.Name))
                        {
                            ModelState.AddModelError("", "Role name must be unique");
                            return(View(model));
                        }
                    }
                    role.Name            = model.Name;
                    db.Entry(role).State = EntityState.Modified;
                    db.SaveChanges();

                    // first remove all role claims for role
                    db.RoleClaims.RemoveRange(role.RoleClaims);
                    // save new role claims to database for role
                    #region addingRoleClaimsToDatabase
                    if (model.BranchMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "BranchMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.RoleMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "RoleMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.CustomerMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "CustomerMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.CustomerAccountMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "CustomerAccountMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.FinancialReport)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "FinancialReport", RoleID = model.RoleId
                        });
                    }

                    if (model.GLMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "GLMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.GLPosting)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "GLPosting", RoleID = model.RoleId
                        });
                    }

                    if (model.PostingAuth)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "PostingAuth", RoleID = model.RoleId
                        });
                    }

                    if (model.AccountConfigMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "AccountConfigMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.RunEOD)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "RunEOD", RoleID = model.RoleId
                        });
                    }

                    if (model.TellerMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "TellerMgt", RoleID = model.RoleId
                        });
                    }

                    if (model.TellerPosting)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "TellerPosting", RoleID = model.RoleId
                        });
                    }

                    if (model.UserMgt)
                    {
                        db.RoleClaims.Add(new RoleClaim {
                            Name = "UserMgt", RoleID = model.RoleId
                        });
                    }
                    #endregion

                    db.SaveChanges();
                    return(RedirectToAction("RoleClaims"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.ToString());
                    return(View(model));
                }
            }
            ModelState.AddModelError("", "Please enter valid data");
            return(View(model));
        }
Example #9
0
        public ActionResult ApproveTellerPost(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TellerPosting tellerPosting = db.TellerPostings.Find(id);

            if (tellerPosting == null)
            {
                return(HttpNotFound());
            }

            var amt = tellerPosting.Amount;

            var tillAct = tellerPosting.TillAccount;
            var custAct = tellerPosting.CustomerAccount;

            if (tellerPosting.PostingType == TellerPostingType.Withdrawal)
            {
                if (custActLogic.CustomerAccountHasSufficientBalance(custAct, amt))
                {
                    if (!(tillAct.AccountBalance >= amt))
                    {
                        // i have no choice but to send the error messages with partial views.
                        return(RedirectToAction("TellerPosts", new { message = "Insuficient funds in till account" }));
                    }

                    //all this is happening after transaction is approved by checker.
                    string result = telPostLogic.PostTeller(custAct, tillAct, amt, TellerPostingType.Withdrawal);
                    if (!result.Equals("success"))
                    {
                        return(RedirectToAction("TellerPosts", new { message = result }));
                    }

                    tellerPosting.Status          = PostStatus.Approved;
                    db.Entry(tellerPosting).State = EntityState.Modified;
                    db.Entry(custAct).State       = EntityState.Modified;
                    db.Entry(tillAct).State       = EntityState.Modified;

                    db.SaveChanges();

                    reportLogic.CreateTransaction(tillAct, amt, TransactionType.Credit);
                    reportLogic.CreateTransaction(custAct, amt, TransactionType.Debit);

                    return(RedirectToAction("TellerPosts", new { message = "Transaction Approved!" }));
                }
                else
                {
                    return(RedirectToAction("TellerPosts", new { message = "Insufficient funds in customer account" }));
                }
            }
            else
            {
                string result = telPostLogic.PostTeller(custAct, tillAct, amt, TellerPostingType.Deposit);
                if (!result.Equals("success"))
                {
                    return(RedirectToAction("TellerPosts", new { message = result }));
                }

                tellerPosting.Status          = PostStatus.Approved;
                db.Entry(tellerPosting).State = EntityState.Modified;
                db.Entry(custAct).State       = EntityState.Modified;
                db.Entry(tillAct).State       = EntityState.Modified;

                db.SaveChanges();

                reportLogic.CreateTransaction(tillAct, amt, TransactionType.Debit);
                reportLogic.CreateTransaction(custAct, amt, TransactionType.Credit);

                return(RedirectToAction("TellerPosts", new { message = "Transaction Approved!" }));
            }
        }