Exemple #1
0
        public ActionResult Create(loans loans)
        {
            if (ModelState.IsValid)
            {
                var existingLoans = db.loans.Where(l => l.LoanOriginatedBy == loans.LoanOriginatedBy &&
                                                   l.IsInactive == false).ToList();

                if (existingLoans.Count > 0)
                {
                    var number = existingLoans.Select(l => new { name = l.CustomerForeName + " " + l.CustomerSurName }).Distinct().ToList();
                    if (number.Count() > 10)
                    {
                        TempData["LoansCreation"] = "An error occured while creating the loan. Managers are not allowed to create loans if more than 10 active customer loans already exists.";
                        return(RedirectToAction("Index"));
                    }
                }

                loans.LoanID = Guid.NewGuid();
                db.loans.Add(loans);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(loans));
        }
Exemple #2
0
        public ActionResult CreateLoan(string ForeName, String LastName)
        {
            loans loan = new loans();

            var customer = db.customers.Where(c => c.ForeName.ToUpper() == ForeName.ToUpper() &&
                                              c.SurName.ToUpper() == LastName.ToUpper()).FirstOrDefault();

            if (customer != null)
            {
                loan.CustomerForeName = customer.ForeName;
                loan.CustomerSurName  = customer.SurName;
                loan.DateOfBirth      = customer.DateofBirth;
            }
            else
            {
                TempData["CustomerInfo"] = "Customer not found. Please reveiw the information or create a customer profile.";
                return(View(loan));
            }
            var lastLoan = db.loans.OrderByDescending(l => l.LoanNumber).FirstOrDefault();

            if (lastLoan == null)
            {
                loan.LoanNumber = nextLoanNum;
            }
            else
            {
                var lastloan = lastLoan.LoanNumber;
                loan.LoanNumber = lastloan + 1;
            }
            return(View(loan));
        }
Exemple #3
0
 public ActionResult Edit([Bind(Include = "LoanID,LoanNumber,LoanType,StartDate,IntrestRate,Value,Duration,IsInactive,CustomerID,LoanOriginatedBy")] loans loans)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loans).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(loans));
 }
Exemple #4
0
        // GET: loans/Details/5
        public ActionResult Details(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            loans loans = db.loans.Find(id);

            if (loans == null)
            {
                return(HttpNotFound());
            }
            return(View(loans));
        }
Exemple #5
0
        public ActionResult DeleteConfirmed(Guid id)
        {
            loans loans = db.loans.Find(id);

            var inactive = loans.IsInactive;

            if (inactive)
            {
                db.loans.Remove(loans);
                db.SaveChanges();
                TempData["Error Deletion"] = "Loan " + loans.LoanNumber + "deleted successfully";
                return(RedirectToAction("Index"));
            }

            TempData["Error Deletion"] = "Error Deleting the loan #" + loans.LoanNumber + ". This Loan is active. Deletion of an actve loans is not permissible";

            return(RedirectToAction("Index"));
        }