.NET Collection Application - Watts' A Loan
.NET Collection Application - Watts' A Loan
Introduction
The .NET Framework various various (types of) collection classes. The library also highly supports serialization. This makes it possible to create completely functional database.
Watts' A Loan is a fictional company that gives loans to individuals and businesses. This application uses the generic List<> collection class to create and manage records for the company.
Practical Learning: Introducing the Application
body { background-color: #370000; } .bold { font-weight: 600; } .yellow { color: #fdfeb0; } .small { width: 20px; } .top-padding { padding-top: 0.50em; } .containment { margin: auto; width: 400px; } .containment1 { margin: auto; width: 500px; } .wheat { color: wheat; } .regular-text { color: azure; } .heading { color: white; background-color: steelblue; } .top-menu-holder { width: 750px; margin: auto; } .bordered { border-radius: 5px; border: 1px solid black; } .menu-box { border-radius: 5px; background-color: burlywood; } .menu-box ul { list-style-type: none; } .jumbotron { background-color: #370000; } .jumbotron h1 { color: wheat; font-weight: 600; text-shadow: 5px 5px black; } .table { color: #fdfeb0; } .wal-lead:link { color: aquamarine; } .wal-lead:active { color: bisque; } .wal-lead:visited { color: yellow; } .wal-lead:hover { color: wheat; text-decoration: underline; } .common-font { font-family: Georgia, Garamond, 'Times New Roman', serif; } .navbar-inverse { background: rgb(2,0,36); background: linear-gradient(180deg, rgba(55,0,0,1) 0%, rgba(120,0,0,1) 100%); } .navbar-inverse .navbar-nav > li > a { height: 75px; padding-top: 30px; color: #9d9d9d; } .navbar-inverse .navbar-nav > li > a:link, .navbar-inverse .navbar-nav > li > a:active, .navbar-inverse .navbar-nav > li > a:visited { color: #fff; background: rgb(2,0,36); background: linear-gradient(180deg, rgba(2,0,36,1) 0%, rgba(186,16,16,1) 49%, rgba(55,0,0,1) 100%); } .navbar-inverse .navbar-nav > li > a:focus { color: #fff; background: rgb(2,0,36); background: linear-gradient(180deg, rgba(55,0,0,1) 100%, rgba(186,16,16,1) 50%, rgba(2,0,36,1) 0%); } .navbar-inverse .navbar-nav > li > a:hover { color: #fff; background: rgb(2,0,236); background: linear-gradient(180deg, rgba(55,0,0,1) 0%, rgba(200,0,0,1) 100%); } .navbar-inverse .navbar-nav > .active > a, .navbar-inverse .navbar-nav > .active > a:hover, .navbar-inverse .navbar-nav > .active > a:focus { color: #fff; background: rgb(2,0,236); background: linear-gradient(180deg, rgba(200,0,0,1) 100%, rgba(55,0,0,1) 0%);} .navbar-inverse .navbar-brand a { height: 75px; padding-top: 30px; color: #9d9d9d; } .navbar-inverse .navbar-brand:link { height: 75px; padding-top: 30px; color: #9d9d9d; background: rgb(2,0,36); background: linear-gradient(180deg, rgba(2,0,36,1) 0%, rgba(186,16,16,1) 49%, rgba(55,0,0,1) 100%); } .navbar-inverse .navbar-brand:focus { color: #9d9d9d; background: rgb(2,0,36); background: linear-gradient(180deg, rgba(55,0,0,1) 100%, rgba(186,16,16,1) 50%, rgba(2,0,36,1) 0%); } .navbar-inverse .navbar-brand:hover { color: #fff; background: rgb(2,0,236); background: linear-gradient(180deg, rgba(55,0,0,1) 0%, rgba(200,0,0,1) 100%); } .navbar-inverse .navbar-brand { color: #fdfeb0; } .navbar-inverse .navbar-brand:hover, .navbar-inverse .navbar-brand:focus { color: #fdfeb0; }
using System.Web.Optimization;
namespace WattsALoan1
{
public class BundleConfig
{
// For more information on bundling, visit https://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/WattsALoan.css"));
}
}
}
Employees
In our application, the employees are the people who will perform all types of data entry for the company. We will need a class that represents a table of records. We will then use a collection class to create and manage records. We will use serialization to save and manage records (editing/updating and deleting).
Practical Learning: Creating a Database
using System; using System.ComponentModel.DataAnnotations; namespace WattsALoan1.Models { [Serializable] public class Employee { [Display(Name = "Employee Id")] public int EmployeeId { get; set; } [Display(Name = "Employee #")] public string EmployeeNumber { get; set; } [Display(Name = "First Name")] public string FirstName { get; set; } [Display(Name = "Last Name")] public string LastName { get; set; } [Display(Name = "Employee Title")] public string EmploymentTitle { get; set; } public string Identification { get { return EmployeeNumber + " - " + FirstName + " " + LastName + " (" + EmploymentTitle + ")"; } } } }
using System.IO; using System.Net; using System.Web.Mvc; using WattsALoan1.Models; using System.Collections.Generic; using System.Runtime.Serialization.Formatters.Binary; namespace WattsALoan1.Controllers { public class EmployeesController : Controller { // GET: Employees public ActionResult Index() { List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using(FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } return View(employees); } // GET: Employees/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } Employee employee = employees.Find(empl => empl.EmployeeId == id); if (employee == null) { return HttpNotFound(); } return View(employee); } // GET: Employees/Create public ActionResult Create() { return View(); } // POST: Employees/Create [HttpPost] public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here int emplId = 0; List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); foreach (Employee empl in employees) { emplId = empl.EmployeeId; } } } emplId++; if (ModelState.IsValid) { Employee staff = new Employee() { EmployeeId = emplId, LastName = collection["LastName"], FirstName = collection["FirstName"], EmployeeNumber = collection["EmployeeNumber"], EmploymentTitle = collection["EmploymentTitle"], }; employees.Add(staff); using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfEmployees.Serialize(fsEmployees, employees); } } return RedirectToAction("Index"); } catch { return View(); } } // GET: Employees/Edit/5 public ActionResult Edit(int ? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } Employee employee = employees.Find(empl => empl.EmployeeId == id); if (employee == null) { return HttpNotFound(); } return View(employee); } // POST: Employees/Edit/5 [HttpPost] public ActionResult Edit(int id, FormCollection collection) { try { // TODO: Add update logic here List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } if (ModelState.IsValid) { foreach (Employee empl in employees) { if (empl.EmployeeId == id) { empl.LastName = collection["LastName"]; empl.FirstName = collection["FirstName"]; empl.EmployeeNumber = collection["EmployeeNumber"]; empl.EmploymentTitle = collection["EmploymentTitle"]; using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfEmployees.Serialize(fsEmployees, employees); } break; } } } return RedirectToAction("Index"); } catch { return View(); } } // GET: Employees/Delete/5 public ActionResult Delete(int ?id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } Employee employee = employees.Find(empl => empl.EmployeeId == id); if (employee == null) { return HttpNotFound(); } return View(employee); } // POST: Employees/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } if (ModelState.IsValid) { foreach (Employee empl in employees) { if (empl.EmployeeId == id) { employees.Remove(empl); using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfEmployees.Serialize(fsEmployees, employees); } break; } } } return RedirectToAction("Index"); } catch { return View(); } } } }
@model IEnumerable<WattsALoan1.Models.Employee> @{ ViewBag.Title = "Index"; } <h2 class="bold wheat common-font text-center">Employees</h2> <table class="table common-font"> <tr> <th class="text-center">@Html.DisplayNameFor(model => model.EmployeeId)</th> <th>@Html.DisplayNameFor(model => model.EmployeeNumber)</th> <th>@Html.DisplayNameFor(model => model.FirstName)</th> <th>@Html.DisplayNameFor(model => model.LastName)</th> <th>@Html.DisplayNameFor(model => model.EmploymentTitle)</th> <th>@Html.ActionLink("Hire New Employee", "Create", null, htmlAttributes: new { @class = "wal-lead" })</th> </tr> @foreach (var item in Model) { <tr> <td class="text-center">@Html.DisplayFor(modelItem => item.EmployeeId)</td> <td>@Html.DisplayFor(modelItem => item.EmployeeNumber)</td> <td>@Html.DisplayFor(modelItem => item.FirstName)</td> <td>@Html.DisplayFor(modelItem => item.LastName)</td> <td>@Html.DisplayFor(modelItem => item.EmploymentTitle)</td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.EmployeeId }, htmlAttributes: new { @class = "wal-lead" }) :: @Html.ActionLink("Details", "Details", new { id = item.EmployeeId }, htmlAttributes: new { @class = "wal-lead" }) :: @Html.ActionLink("Delete", "Delete", new { id = item.EmployeeId }, htmlAttributes: new { @class = "wal-lead" }) </td> </tr> } </table>
@model WattsALoan1.Models.Employee @{ ViewBag.Title = "Create Employee"; } <h2 class="bold wheat common-font text-center">Employment Application</h2> <hr /> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal common-font"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.EmployeeNumber, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.EmployeeNumber, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.EmployeeNumber, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.EmploymentTitle, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.EmploymentTitle, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.EmploymentTitle, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label class="control-label col-md-6">@Html.ActionLink("Employees", "Index", null, htmlAttributes: new { @class = "wal-lead" })</label> <div class="col-md-6"> <input type="submit" value="Hire this Employee" class="btn btn-warning" /> </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
@model WattsALoan1.Models.Employee @{ ViewBag.Title = "Delete Employee"; } <h2 class="bold common-font text-center wheat">Delete Employee Record</h2> <hr /> <h3 class="common-font wheat text-center">Are you sure you want to delete this?</h3> <div class="containment"> <dl class="dl-horizontal common-font wheat"> <dt>@Html.DisplayNameFor(model => model.EmployeeId)</dt> <dd>@Html.DisplayFor(model => model.EmployeeId)</dd> <dt>@Html.DisplayNameFor(model => model.EmployeeNumber)</dt> <dd>@Html.DisplayFor(model => model.EmployeeNumber)</dd> <dt>@Html.DisplayNameFor(model => model.FirstName)</dt> <dd>@Html.DisplayFor(model => model.FirstName)</dd> <dt>@Html.DisplayNameFor(model => model.LastName)</dt> <dd>@Html.DisplayFor(model => model.LastName)</dd> <dt>@Html.DisplayNameFor(model => model.EmploymentTitle)</dt> <dd>@Html.DisplayFor(model => model.EmploymentTitle)</dd> </dl> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-actions no-color"> <input type="submit" value="Delete Employee" class="btn btn-warning" /> :: @Html.ActionLink("Employees", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </div> } </div>
@model WattsALoan1.Models.Employee @{ ViewBag.Title = "Employee Details"; } <h2 class="bold text-center common-font wheat">Employee Details</h2> <hr /> <div class="containment"> <dl class="dl-horizontal common-font wheat"> <dt>@Html.DisplayNameFor(model => model.EmployeeId)</dt> <dd>@Html.DisplayFor(model => model.EmployeeId)</dd> <dt>@Html.DisplayNameFor(model => model.EmployeeNumber)</dt> <dd>@Html.DisplayFor(model => model.EmployeeNumber)</dd> <dt>@Html.DisplayNameFor(model => model.FirstName)</dt> <dd>@Html.DisplayFor(model => model.FirstName)</dd> <dt>@Html.DisplayNameFor(model => model.LastName)</dt> <dd>@Html.DisplayFor(model => model.LastName)</dd> <dt>@Html.DisplayNameFor(model => model.EmploymentTitle)</dt> <dd>@Html.DisplayFor(model => model.EmploymentTitle)</dd> </dl> </div> <p class="text-center"> @Html.ActionLink("Edit Employee Details", "Edit", new { id = Model.EmployeeId }, htmlAttributes: new { @class = "wal-lead" }) :: @Html.ActionLink("Employees", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </p>
@model WattsALoan1.Models.Employee @{ ViewBag.Title = "Edit/Update Employee Information"; } <h2 class="bold wheat common-font text-center">Edit/Update Employee Information</h2> <hr /> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal common-font"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.EmployeeId) <div class="form-group"> @Html.LabelFor(model => model.EmployeeNumber, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.EmployeeNumber, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.EmployeeNumber, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.EmploymentTitle, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.EmploymentTitle, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.EmploymentTitle, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label class="control-label col-md-6"> @Html.ActionLink("Employees", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </label> <div class="col-md-6"> <input type="submit" value="Update Employee Record" class="btn btn-warning" /> </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
Loans Contracts
A loan contract establishes a relationship between the lending company and a client. For our application, we will create a table that lays out the foundation of a contract. We will mimic a relational database. In this case, the table for loan contract will have a property (foreign key) that represents the employees. When it comes to calculations, to keep our application simple, we will not perform any operation. The company will train employees for all aspects of data entry, including the ability to specify the loan amount, the interest rate, the number of months for financing, etc.
Practical Learning: Creating Loans Contracts
using System; using System.ComponentModel.DataAnnotations; namespace WattsALoan1.Models { [Serializable] public class LoanContract { [Display(Name = "Loan Contract Id")] public int LoanContractId { get; set; } [Display(Name = "Loan #")] public int LoanNumber { get; set; } [Display(Name = "Date Allocated")] public string DateAllocated { get; set; } public int? EmployeeId { get; set; } [Display(Name = "First Name")] public string CustomerFirstName { get; set; } [Display(Name = "Last Name")] public string CustomerLastName { get; set; } [Display(Name = "Loan Type")] public string LoanType { get; set; } [Display(Name = "Loan Amount")] public string LoanAmount { get; set; } [Display(Name = "Interest Rate")] public string InterestRate { get; set; } public string Periods { get; set; } [Display(Name = "Monthly Payment")] public string MonthlyPayment { get; set; } [Display(Name = "Future Value")] public string FutureValue { get; set; } [Display(Name = "Interest Amount")] public string InterestAmount { get; set; } [Display(Name = "Payment Start Date")] public string PaymentStartDate { get; set; } public string Identification { get { return LoanContractId + " - " + LoanNumber + " as " + LoanType + " to " + CustomerFirstName + " " + CustomerLastName + " for " + LoanAmount + " (" + MonthlyPayment + "/month)"; } } } }
using System; using System.IO; using System.Net; using System.Web.Mvc; using WattsALoan1.Models; using System.Collections.Generic; using System.Runtime.Serialization.Formatters.Binary; namespace WattsALoan1.Controllers { public class LoansContractsController : Controller { // GET: LoansContracts public ActionResult Index() { BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["Employees"] = employees; return View(loansContracts); } // GET: LoansContracts/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } LoanContract contract = loansContracts.Find(lc => lc.LoanContractId == id); if (contract == null) { return HttpNotFound(); } List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } List<Payment> pastPayments = new List<Payment>(); foreach(Payment pmt in payments) { if( pmt.LoanContractId == id) { pastPayments.Add(pmt); } } ViewData["PastPayments"] = pastPayments; List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["Clerk"] = employees[(int)contract.EmployeeId - 1].Identification; ViewData["Employees"] = employees; return View(contract); } // GET: LoansContracts/Create public ActionResult Create() { Random rndNumber = new Random(); ViewData["LoanNumber"] = rndNumber.Next(100001, 999999); // Create a list of loans types for a combo box List<SelectListItem> loanTypes = new List<SelectListItem>(); loanTypes.Add(new SelectListItem() { Text = "Personal Loan", Value = "Personal Loan" }); loanTypes.Add(new SelectListItem() { Text = "Car Financing", Value = "Car Financing" }); loanTypes.Add(new SelectListItem() { Text = "Boat Financing", Value = "Boat Financing" }); loanTypes.Add(new SelectListItem() { Text = "Furniture Purchase", Value = "Furniture Purchase" }); loanTypes.Add(new SelectListItem() { Text = "Musical Instrument", Value = "Musical Instrument" }); // Store the list in a View Bag so it can be access by a combo box ViewData["LoanType"] = loanTypes; List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["EmployeeId"] = new SelectList(employees, "EmployeeId", "Identification"); return View(); } // POST: LoansContracts/Create [HttpPost] public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here int contractId = 0; List<LoanContract> loansContracts = new List<LoanContract>(); BinaryFormatter bfLoansContracts = new BinaryFormatter(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); foreach (LoanContract lc in loansContracts) { contractId = lc.LoanContractId; } } } contractId++; if (ModelState.IsValid) { LoanContract contract = new LoanContract() { LoanContractId = contractId, LoanNumber = int.Parse(collection["LoanNumber"]), DateAllocated = collection["DateAllocated"], EmployeeId = int.Parse(collection["EmployeeId"]), CustomerLastName = collection["CustomerLastName"], CustomerFirstName = collection["CustomerFirstName"], LoanType = collection["LoanType"], LoanAmount = collection["LoanAmount"], InterestRate = collection["InterestRate"], Periods = collection["Periods"], MonthlyPayment = collection["MonthlyPayment"], FutureValue = collection["FutureValue"], InterestAmount = collection["InterestAmount"], PaymentStartDate = collection["PaymentStartDate"] }; loansContracts.Add(contract); using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfLoansContracts.Serialize(fsLoansContracts, loansContracts); } } return RedirectToAction("Index"); } catch { return View(); } } // GET: LoansContracts/Edit/5 public ActionResult Edit(int ? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } LoanContract contract = loansContracts.Find(lc => lc.LoanContractId == id); if (contract == null) { return HttpNotFound(); } List<string> loanTypes = new List<string>(); loanTypes.Add("Personal Loan"); loanTypes.Add("Car Financing"); loanTypes.Add("Boat Financing"); loanTypes.Add("Furniture Purchase"); loanTypes.Add("Musical Instrument"); ViewData["LoanType"] = new SelectList(loanTypes, "LoanType", "LoanType"); List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["EmployeeId"] = new SelectList(employees, "EmployeeId", "Identification", contract.EmployeeId); return View(contract); } // POST: LoansContracts/Edit/5 [HttpPost] public ActionResult Edit(int id, FormCollection collection) { try { // TODO: Add update logic here BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } if (ModelState.IsValid) { foreach (LoanContract contract in loansContracts) { if (contract.LoanContractId == id) { contract.LoanNumber = int.Parse(collection["LoanNumber"]); contract.DateAllocated = collection["DateAllocated"]; contract.EmployeeId = int.Parse(collection["EmployeeId"]); contract.CustomerFirstName = collection["CustomerFirstName"]; contract.CustomerLastName = collection["CustomerLastName"]; contract.LoanType = collection["LoanType"]; contract.LoanAmount = collection["LoanAmount"]; contract.InterestRate = collection["InterestRate"]; contract.Periods = collection["Periods"]; contract.MonthlyPayment = collection["MonthlyPayment"]; contract.FutureValue = collection["FutureValue"]; contract.InterestAmount = collection["InterestAmount"]; contract.PaymentStartDate = collection["PaymentStartDate"]; using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfLoansContracts.Serialize(fsLoansContracts, loansContracts); } break; } } } return RedirectToAction("Index"); } catch { return View(); } } // GET: LoansContracts/Delete/5 public ActionResult Delete(int ?id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } LoanContract contract = loansContracts.Find(lc => lc.LoanContractId == id); if (contract == null) { return HttpNotFound(); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["Clerk"] = employees[(int)contract.EmployeeId - 1].Identification; return View(contract); } // POST: LoansContracts/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } if (ModelState.IsValid) { foreach (LoanContract contract in loansContracts) { if (contract.LoanContractId == id) { loansContracts.Remove(contract); using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfLoansContracts.Serialize(fsLoansContracts, loansContracts); } break; } } } return RedirectToAction("Index"); } catch { return View(); } } } }
@model IEnumerable<WattsALoan1.Models.LoanContract> @{ ViewBag.Title = "Loans Contracts"; List<WattsALoan1.Models.Employee> employees = ViewData["Employees"] as List<WattsALoan1.Models.Employee>; } <h2 class="bold wheat common-font text-center">Loans Contracts</h2> <table class="table common-font"> <tr> <th class="text-center">@Html.DisplayNameFor(model => model.LoanContractId)</th> <th class="text-center">Processed By</th> <th class="text-center">@Html.DisplayNameFor(model => model.LoanNumber)</th> <th class="text-center">@Html.DisplayNameFor(model => model.DateAllocated)</th> <th>@Html.DisplayNameFor(model => model.CustomerFirstName)</th> <th>@Html.DisplayNameFor(model => model.CustomerLastName)</th> <th>@Html.DisplayNameFor(model => model.LoanType)</th> <th>@Html.DisplayNameFor(model => model.LoanAmount)</th> <th>@Html.DisplayNameFor(model => model.InterestRate)</th> <th>@Html.DisplayNameFor(model => model.Periods)</th> <th>@Html.DisplayNameFor(model => model.MonthlyPayment)</th> <th>@Html.DisplayNameFor(model => model.FutureValue)</th> <th>@Html.DisplayNameFor(model => model.InterestAmount)</th> <th class="text-center">@Html.DisplayNameFor(model => model.PaymentStartDate)</th> <th>@Html.ActionLink("Create Loan Contract", "Create", null, htmlAttributes: new { @class = "wal-lead" })</th> </tr> @foreach (var item in Model) { int i = int.Parse(Html.DisplayFor(modelItem => item.EmployeeId).ToHtmlString()); string staff = employees[i - 1].Identification; <tr> <td class="text-center">@Html.DisplayFor(modelItem => item.LoanContractId)</td> <td class="text-center">@staff</td> <td class="text-center">@Html.DisplayFor(modelItem => item.LoanNumber)</td> <td class="text-center">@Html.DisplayFor(modelItem => item.DateAllocated)</td> <td>@Html.DisplayFor(modelItem => item.CustomerFirstName)</td> <td>@Html.DisplayFor(modelItem => item.CustomerLastName)</td> <td>@Html.DisplayFor(modelItem => item.LoanType)</td> <td>@Html.DisplayFor(modelItem => item.LoanAmount)</td> <td>@Html.DisplayFor(modelItem => item.InterestRate)</td> <td>@Html.DisplayFor(modelItem => item.Periods)</td> <td>@Html.DisplayFor(modelItem => item.MonthlyPayment)</td> <td>@Html.DisplayFor(modelItem => item.FutureValue)</td> <td>@Html.DisplayFor(modelItem => item.InterestAmount)</td> <td class="text-center">@Html.DisplayFor(modelItem => item.PaymentStartDate)</td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.LoanContractId }, htmlAttributes: new { @class = "wal-lead" }) | @Html.ActionLink("Details", "Details", new { id = item.LoanContractId }, htmlAttributes: new { @class = "wal-lead" }) | @Html.ActionLink("Delete", "Delete", new { id = item.LoanContractId }, htmlAttributes: new { @class = "wal-lead" }) </td> </tr> } </table>
@model WattsALoan1.Models.LoanContract @{ ViewBag.Title = "Create Loan Contract"; } <h2 class="bold wheat common-font text-center">Create Loan Contract</h2> <hr /> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal common-font"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.LoanNumber, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.TextBox("LoanNumber", ViewData["LoanNumber"], htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.LoanNumber, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.DateAllocated, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.DateAllocated, new { htmlAttributes = new { @class = "form-control", type = "Date" } }) @Html.ValidationMessageFor(model => model.DateAllocated, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label for="emplID" class="control-label col-md-5 yellow">Processed By</label> <div class="col-md-7"> @Html.DropDownList("EmployeeId", null, htmlAttributes: new { @class = "form-control", id = "emplID" }) @Html.ValidationMessageFor(model => model.EmployeeId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.CustomerFirstName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.CustomerFirstName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CustomerFirstName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.CustomerLastName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.CustomerLastName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CustomerLastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.LoanType, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.DropDownList("LoanType", ViewBag.LoansTypes as SelectList, htmlAttributes: new { @class = "form-control col-md-5 blue" }) @Html.ValidationMessageFor(model => model.LoanType, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.LoanAmount, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.LoanAmount, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LoanAmount, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InterestRate, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.InterestRate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InterestRate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Periods, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.Periods, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Periods, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.MonthlyPayment, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.MonthlyPayment, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.MonthlyPayment, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.FutureValue, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.FutureValue, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.FutureValue, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InterestAmount, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.InterestAmount, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InterestAmount, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PaymentStartDate, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.PaymentStartDate, new { htmlAttributes = new { @class = "form-control", type = "Date" } }) @Html.ValidationMessageFor(model => model.PaymentStartDate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label class="control-label col-md-6">@Html.ActionLink("Loans Contracts", "Index", null, htmlAttributes: new { @class = "wal-lead" })</label> <div class="col-md-6"> <input type="submit" value="Create Loan Contract" class="btn btn-warning" /> </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
@model WattsALoan1.Models.LoanContract @{ ViewBag.Title = "Delete Loan Contract"; List<WattsALoan1.Models.Employee> employees = ViewData["Employees"] as List<WattsALoan1.Models.Employee>; } <h2 class="bold common-font text-center wheat">Delete Loan Contract</h2> <hr /> <h3 class="common-font wheat text-center">Are you sure you want to delete this?</h3> <div class="containment"> <dl class="dl-horizontal common-font wheat"> <dt>@Html.DisplayNameFor(model => model.LoanContractId)</dt> <dd>@Html.DisplayFor(model => model.LoanContractId)</dd> <dt>Processed By</dt> <dd>@ViewData["Clerk"]</dd> <dt>@Html.DisplayNameFor(model => model.LoanNumber)</dt> <dd>@Html.DisplayFor(model => model.LoanNumber)</dd> <dt>@Html.DisplayNameFor(model => model.DateAllocated)</dt> <dd>@Html.DisplayFor(model => model.DateAllocated)</dd> <dt>@Html.DisplayNameFor(model => model.CustomerFirstName)</dt> <dd>@Html.DisplayFor(model => model.CustomerFirstName)</dd> <dt>@Html.DisplayNameFor(model => model.CustomerLastName)</dt> <dd>@Html.DisplayFor(model => model.CustomerLastName)</dd> <dt>@Html.DisplayNameFor(model => model.LoanType)</dt> <dd>@Html.DisplayFor(model => model.LoanType)</dd> <dt>@Html.DisplayNameFor(model => model.LoanAmount)</dt> <dd>@Html.DisplayFor(model => model.LoanAmount)</dd> <dt>@Html.DisplayNameFor(model => model.InterestRate)</dt> <dd>@Html.DisplayFor(model => model.InterestRate)</dd> <dt>@Html.DisplayNameFor(model => model.Periods)</dt> <dd>@Html.DisplayFor(model => model.Periods)</dd> <dt>@Html.DisplayNameFor(model => model.MonthlyPayment)</dt> <dd>@Html.DisplayFor(model => model.MonthlyPayment)</dd> <dt>@Html.DisplayNameFor(model => model.FutureValue)</dt> <dd>@Html.DisplayFor(model => model.FutureValue)</dd> <dt>@Html.DisplayNameFor(model => model.InterestAmount)</dt> <dd>@Html.DisplayFor(model => model.InterestAmount)</dd> <dt>@Html.DisplayNameFor(model => model.PaymentStartDate)</dt> <dd>@Html.DisplayFor(model => model.PaymentStartDate)</dd> </dl> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-actions no-color"> <input type="submit" value="Delete this Loan Contract" class="btn btn-warning" /> | @Html.ActionLink("Loans Contracts", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </div> } </div>
@model WattsALoan1.Models.LoanContract @{ ViewBag.Title = "Edit/Update Loan Contract"; } <h2 class="bold wheat common-font text-center">Edit/Update Loan Contract</h2> <hr /> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal common-font"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.LoanContractId) <div class="form-group"> @Html.LabelFor(model => model.LoanNumber, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.LoanNumber, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LoanNumber, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.DateAllocated, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.DateAllocated, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.DateAllocated, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label for="emplID" class="control-label col-md-5 yellow">Processed By</label> <div class="col-md-7"> @Html.DropDownList("EmployeeId", null, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.EmployeeId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.CustomerFirstName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.CustomerFirstName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CustomerFirstName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.CustomerLastName, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.CustomerLastName, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.CustomerLastName, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.LoanType, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.LoanType, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LoanType, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.LoanAmount, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.LoanAmount, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.LoanAmount, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InterestRate, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.InterestRate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InterestRate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Periods, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.Periods, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Periods, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.MonthlyPayment, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.MonthlyPayment, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.MonthlyPayment, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.FutureValue, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.FutureValue, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.FutureValue, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.InterestAmount, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.InterestAmount, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.InterestAmount, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PaymentStartDate, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.PaymentStartDate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PaymentStartDate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label class="control-label col-md-6"> @Html.ActionLink("Loans Contracts", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </label> <div class="col-md-6"> <input type="submit" value="Update this Loan Contract" class="btn btn-warning" /> </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
Payments
For our application, we need to assist users in handling loans payments. To start, we will create a table that represents a typical payment record. Because this is a collection-based application, once again, we will create, save, and manage records through serialization.
Practical Learning: Introducing Child Nodes
using System; using System.ComponentModel.DataAnnotations; namespace WattsALoan1.Models { [Serializable] public class Payment { [Display(Name = "Payment Id")] public int PaymentId { get; set; } [Display(Name = "Receipt #")] public int? ReceiptNumber { get; set; } [Display(Name = "Payment Date")] public string PaymentDate { get; set; } public int? EmployeeId { get; set; } public int? LoanContractId { get; set; } [Display(Name = "Payment Amount")] public string PaymentAmount { get; set; } public string Balance { get; set; } } }
using System; using System.IO; using System.Net; using System.Web.Mvc; using WattsALoan1.Models; using System.Collections.Generic; using System.Runtime.Serialization.Formatters.Binary; namespace WattsALoan1.Controllers { public class PaymentsController : Controller { // GET: Payments public ActionResult Index() { List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments= new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } ViewData["Employees"] = employees; ViewData["LoansContracts"] = loansContracts; return View(payments); } // GET: Payments/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } Payment pmt = payments.Find(p => p.PaymentId == id); if (pmt == null) { return HttpNotFound(); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["Clerk"] = employees[(int)pmt.EmployeeId - 1].Identification; BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } ViewData["LoanDetails"] = loansContracts[(int)pmt.LoanContractId - 1].Identification; return View(pmt); } // GET: Payments/Create public ActionResult Create() { Random rndNumber = new Random(); ViewData["ReceiptNumber"] = rndNumber.Next(100001, 999999); List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } ViewData["EmployeeId"] = new SelectList(employees, "EmployeeId", "Identification"); ViewData["LoanContractId"] = new SelectList(loansContracts, "LoanContractId", "Identification"); return View(); } // POST: Payments/Create [HttpPost] public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here int pmtId = 0; List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); foreach (Payment pmt in payments) { pmtId = pmt.PaymentId; } } } pmtId++; if (ModelState.IsValid) { Payment pay = new Payment() { PaymentId = pmtId, ReceiptNumber = int.Parse(collection["ReceiptNumber"]), PaymentDate = collection["PaymentDate"], EmployeeId = int.Parse(collection["EmployeeId"]), LoanContractId = int.Parse(collection["LoanContractId"]), PaymentAmount = collection["PaymentAmount"], Balance = collection["Balance"] }; payments.Add(pay); using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfPayments.Serialize(fsPayments, payments); } } return RedirectToAction("Index"); } catch { return View(); } } // GET: Payments/Edit/5 public ActionResult Edit(int ? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } Payment pmt = payments.Find(p => p.PaymentId == id); if (pmt == null) { return HttpNotFound(); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } ViewData["EmployeeId"] = new SelectList(employees, "EmployeeId", "Identification", pmt.EmployeeId); ViewData["LoanContractId"] = new SelectList(loansContracts, "LoanContractId", "Identification", pmt.LoanContractId); return View(pmt); } // POST: Payments/Edit/5 [HttpPost] public ActionResult Edit(int id, FormCollection collection) { try { // TODO: Add update logic here List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } if (ModelState.IsValid) { foreach (Payment pmt in payments) { if (pmt.PaymentId == id) { pmt.ReceiptNumber = int.Parse(collection["ReceiptNumber"]); pmt.PaymentDate = collection["PaymentDate"]; pmt.EmployeeId = int.Parse(collection["EmployeeId"]); pmt.LoanContractId = int.Parse(collection["LoanContractId"]); pmt.PaymentAmount = collection["PaymentAmount"]; pmt.Balance = collection["Balance"]; using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfPayments.Serialize(fsPayments, payments); } break; } } } return RedirectToAction("Index"); } catch { return View(); } } // GET: Payments/Delete/5 public ActionResult Delete(int ?id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } Payment pmt = payments.Find(p => p.PaymentId == id); if (pmt == null) { return HttpNotFound(); } List<Employee> employees = new List<Employee>(); BinaryFormatter bfEmployees = new BinaryFormatter(); string strFileEmployees = Server.MapPath("~/App_Data/Employees.wal"); if (System.IO.File.Exists(strFileEmployees)) { using (FileStream fsEmployees = new FileStream(strFileEmployees, FileMode.Open, FileAccess.Read, FileShare.Read)) { employees = (List<Employee>)bfEmployees.Deserialize(fsEmployees); } } ViewData["Clerk"] = employees[(int)pmt.EmployeeId - 1].Identification; BinaryFormatter bfLoansContracts = new BinaryFormatter(); List<LoanContract> loansContracts = new List<LoanContract>(); string strFileLoansContracts = Server.MapPath("~/App_Data/LoansContracts.wal"); if (System.IO.File.Exists(strFileLoansContracts)) { using (FileStream fsLoansContracts = new FileStream(strFileLoansContracts, FileMode.Open, FileAccess.Read, FileShare.Read)) { loansContracts = (List<LoanContract>)bfLoansContracts.Deserialize(fsLoansContracts); } } ViewData["LoanDetails"] = loansContracts[(int)pmt.LoanContractId - 1].Identification; return View(pmt); } // POST: Payments/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here List<Payment> payments = new List<Payment>(); BinaryFormatter bfPayments = new BinaryFormatter(); string strFilePayments = Server.MapPath("~/App_Data/Payments.wal"); if (System.IO.File.Exists(strFilePayments)) { using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read)) { payments = (List<Payment>)bfPayments.Deserialize(fsPayments); } } if (ModelState.IsValid) { foreach (Payment pmt in payments) { if (pmt.PaymentId == id) { payments.Remove(pmt); using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { bfPayments.Serialize(fsPayments, payments); } break; } } } return RedirectToAction("Index"); } catch { return View(); } } } }
@model IEnumerable<WattsALoan1.Models.Payment> @{ ViewBag.Title = "Loans Payments"; List<WattsALoan1.Models.Employee> employees = ViewData["Employees"] as List<WattsALoan1.Models.Employee>; List<WattsALoan1.Models.LoanContract> loans = ViewData["LoansContracts"] as List<WattsALoan1.Models.LoanContract>; } <h2 class="bold wheat common-font text-center">Loans Payments</h2> <table class="table common-font"> <tr> <th class="text-center">@Html.DisplayNameFor(model => model.PaymentId)</th> <th class="text-center">@Html.DisplayNameFor(model => model.ReceiptNumber)</th> <th class="text-center">@Html.DisplayNameFor(model => model.PaymentDate)</th> <th class="text-center">Clerk</th> <th class="text-center">@Html.DisplayNameFor(model => model.LoanContractId)</th> <th>@Html.DisplayNameFor(model => model.PaymentAmount)</th> <th>@Html.DisplayNameFor(model => model.Balance)</th> <th>@Html.ActionLink("Make Loan Payment", "Create", null, htmlAttributes: new { @class = "wal-lead" })</th> </tr> @foreach (var item in Model) { int i = int.Parse(Html.DisplayFor(modelItem => item.EmployeeId).ToHtmlString()); int j = int.Parse(Html.DisplayFor(modelItem => item.LoanContractId).ToHtmlString()); <tr> <td class="text-center">@Html.DisplayFor(modelItem => item.PaymentId)</td> <td class="text-center">@Html.DisplayFor(modelItem => item.ReceiptNumber)</td> <td class="text-center">@Html.DisplayFor(modelItem => item.PaymentDate)</td> <td class="text-center">@employees[i - 1].Identification</td> <td class="text-center">@loans[j - 1].Identification)</td> <td>@Html.DisplayFor(modelItem => item.PaymentAmount)</td> <td>@Html.DisplayFor(modelItem => item.Balance)</td> <td> @Html.ActionLink("Edit", "Edit", new { id = item.PaymentId }, htmlAttributes: new { @class = "wal-lead" }) :: @Html.ActionLink("Details", "Details", new { id = item.PaymentId }, htmlAttributes: new { @class = "wal-lead" }) :: @Html.ActionLink("Delete", "Delete", new { id = item.PaymentId }, htmlAttributes: new { @class = "wal-lead" }) </td> </tr> } </table>
@model WattsALoan1.Models.Payment @{ ViewBag.Title = "Create Payment"; } <h2 class="bold wheat common-font text-center">Create Loan Payment</h2> <hr /> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal common-font"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group"> @Html.LabelFor(model => model.ReceiptNumber, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.TextBox("ReceiptNumber", ViewData["ReceiptNumber"], htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.ReceiptNumber, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PaymentDate, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.PaymentDate, new { htmlAttributes = new { @class = "form-control", type = "Date" } }) @Html.ValidationMessageFor(model => model.PaymentDate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label for="emplID" class="control-label col-md-5 yellow">Processed By</label> <div class="col-md-7"> @Html.DropDownList("EmployeeId", null, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.EmployeeId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label for="emplID" class="control-label col-md-5 yellow">Loan Contract</label> <div class="col-md-7"> @Html.DropDownList("LoanContractId", null, htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.LoanContractId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PaymentAmount, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.PaymentAmount, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PaymentAmount, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Balance, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.Balance, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Balance, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label class="control-label col-md-6"> @Html.ActionLink("Loans Payments", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </label> <div class="col-md-6"> <input type="submit" value="Create Loan Payment" class="btn btn-warning" /> </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
@model WattsALoan1.Models.Payment @{ ViewBag.Title = "Delete Payment"; } <h2 class="bold common-font text-center wheat">Delete Payment</h2> <hr /> <h3 class="common-font wheat text-center">Are you sure you want to cancel this loan payment?</h3> <div class="containment"> <dl class="dl-horizontal common-font wheat"> <dt>@Html.DisplayNameFor(model => model.PaymentId)</dt> <dd>@Html.DisplayFor(model => model.PaymentId)</dd> <dt>Processed By</dt> <dd>@ViewData["Clerk"]</dd> <dt>Loan Details</dt> <dd>@ViewData["LoanDetails"]</dd> <dt>@Html.DisplayNameFor(model => model.ReceiptNumber)</dt> <dd>@Html.DisplayFor(model => model.ReceiptNumber)</dd> <dt>@Html.DisplayNameFor(model => model.PaymentDate)</dt> <dd>@Html.DisplayFor(model => model.PaymentDate)</dd> <dt>@Html.DisplayNameFor(model => model.PaymentAmount)</dt> <dd>@Html.DisplayFor(model => model.PaymentAmount)</dd> <dt>@Html.DisplayNameFor(model => model.Balance)</dt> <dd>@Html.DisplayFor(model => model.Balance)</dd> </dl> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-actions no-color"> <input type="submit" value="Delete Loan Payment" class="btn btn-warning" /> :: @Html.ActionLink("Loans Payments", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </div> } </div>
@model WattsALoan1.Models.Payment @{ ViewBag.Title = "Payment Details"; } <h2 class="bold text-center common-font wheat">Payment Details</h2> <hr /> <div class="containment"> <dl class="dl-horizontal common-font wheat"> <dt>@Html.DisplayNameFor(model => model.PaymentId)</dt> <dd>@Html.DisplayFor(model => model.PaymentId)</dd> <dt>Processed By</dt> <dd>@ViewData["Clerk"]</dd> <dt>Loan Details</dt> <dd>@ViewData["LoanDetails"]</dd> <dt>@Html.DisplayNameFor(model => model.ReceiptNumber)</dt> <dd>@Html.DisplayFor(model => model.ReceiptNumber)</dd> <dt>@Html.DisplayNameFor(model => model.PaymentDate)</dt> <dd>@Html.DisplayFor(model => model.PaymentDate)</dd> <dt>@Html.DisplayNameFor(model => model.PaymentAmount)</dt> <dd>@Html.DisplayFor(model => model.PaymentAmount)</dd> <dt>@Html.DisplayNameFor(model => model.Balance)</dt> <dd>@Html.DisplayFor(model => model.Balance)</dd> </dl> </div> <p class="text-center"> @Html.ActionLink("Edit this Loan Payment", "Edit", new { id = Model.PaymentId }, htmlAttributes: new { @class = "wal-lead" }) | @Html.ActionLink("Loans Payments", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </p>
@model WattsALoan1.Models.Payment @{ ViewBag.Title = "Edit/Update Loan Payment"; } <h2 class="bold wheat common-font text-center">Edit/Update Loan Payment</h2> <hr /> @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="form-horizontal common-font"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) @Html.HiddenFor(model => model.PaymentId) <div class="form-group"> @Html.LabelFor(model => model.ReceiptNumber, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.ReceiptNumber, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.ReceiptNumber, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PaymentDate, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.PaymentDate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PaymentDate, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label for="emplID" class="control-label col-md-5 yellow">Processed By</label> <div class="col-md-7"> @Html.DropDownList("EmployeeId", null, htmlAttributes: new { @class = "form-control", id = "emplID" }) @Html.ValidationMessageFor(model => model.EmployeeId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label for="loanID" class="control-label col-md-5 yellow">Loan Contract</label> <div class="col-md-7"> @Html.DropDownList("LoanContractId", null, htmlAttributes: new { @class = "form-control", id = "loanID" }) @Html.ValidationMessageFor(model => model.LoanContractId, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PaymentAmount, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.PaymentAmount, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.PaymentAmount, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Balance, htmlAttributes: new { @class = "control-label col-md-5 yellow" }) <div class="col-md-7"> @Html.EditorFor(model => model.Balance, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.Balance, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <label class="control-label col-md-6"> @Html.ActionLink("Loans Payments", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </label> <div class="col-md-6"> <input type="submit" value="Update this Loan Payment" class="btn btn-warning" /> </div> </div> </div> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") }
A Summary of the Payments of a Loan
When you access the view that displays loans contracts, when you click the Details link of a certain loan contract, it could be convenient to see a summary of payments of that particular loan. To prepare for this, we created a list of employees in the Details() method of the LoansContractsController class. We can simply access that list in the Details view of the loans..
Practical Learning: Viewing the Payments of a Loan
@model WattsALoan1.Models.LoanContract @{ ViewBag.Title = "Loan Contract Details"; List<WattsALoan1.Models.Employee> employees = ViewData["Employees"] as List<WattsALoan1.Models.Employee>; } <h2 class="bold text-center common-font wheat">Loan Contract Details</h2> <hr /> <div class="containment"> <dl class="dl-horizontal common-font wheat"> <dt>@Html.DisplayNameFor(model => model.LoanContractId)</dt> <dd>@Html.DisplayFor(model => model.LoanContractId)</dd> <dt>Processed By</dt> <dd>@ViewData["Clerk"]</dd> <dt>@Html.DisplayNameFor(model => model.LoanNumber)</dt> <dd>@Html.DisplayFor(model => model.LoanNumber)</dd> <dt>@Html.DisplayNameFor(model => model.DateAllocated)</dt> <dd>@Html.DisplayFor(model => model.DateAllocated)</dd> <dt>@Html.DisplayNameFor(model => model.CustomerFirstName)</dt> <dd>@Html.DisplayFor(model => model.CustomerFirstName)</dd> <dt>@Html.DisplayNameFor(model => model.CustomerLastName)</dt> <dd>@Html.DisplayFor(model => model.CustomerLastName)</dd> <dt>@Html.DisplayNameFor(model => model.LoanType)</dt> <dd>@Html.DisplayFor(model => model.LoanType)</dd> <dt>@Html.DisplayNameFor(model => model.LoanAmount)</dt> <dd>@Html.DisplayFor(model => model.LoanAmount)</dd> <dt>@Html.DisplayNameFor(model => model.InterestRate)</dt> <dd>@Html.DisplayFor(model => model.InterestRate)</dd> <dt>@Html.DisplayNameFor(model => model.Periods)</dt> <dd>@Html.DisplayFor(model => model.Periods)</dd> <dt>@Html.DisplayNameFor(model => model.MonthlyPayment)</dt> <dd>@Html.DisplayFor(model => model.MonthlyPayment)</dd> <dt>@Html.DisplayNameFor(model => model.FutureValue)</dt> <dd>@Html.DisplayFor(model => model.FutureValue)</dd> <dt>@Html.DisplayNameFor(model => model.InterestAmount)</dt> <dd>@Html.DisplayFor(model => model.InterestAmount)</dd> <dt>@Html.DisplayNameFor(model => model.PaymentStartDate)</dt> <dd>@Html.DisplayFor(model => model.PaymentStartDate)</dd> </dl> </div> <hr /> <h2 class="bold wheat common-font text-center">Loan Payments</h2> <table class="table common-font"> <tr> <th class="text-center">Payment Id</th> <th class="text-center">Receipt #</th> <th>Payment Date</th> <th>Processed By</th> <th>Pmt Amt</th> <th>Balance</th> </tr> @foreach (var item in ViewData["PastPayments"] as System.Collections.Generic.List<WattsALoan1.Models.Payment>) { int i = int.Parse(Html.DisplayFor(modelItem => item.EmployeeId).ToHtmlString()); <tr> <td class="text-center">@Html.DisplayFor(modelItem => item.PaymentId)</td> <td class="text-center">@Html.DisplayFor(modelItem => item.ReceiptNumber)</td> <td>@Html.DisplayFor(modelItem => item.PaymentDate)</td> <td>@employees[i - 1].Identification</td> <td>@Html.DisplayFor(modelItem => item.PaymentAmount)</td> <td>@Html.DisplayFor(modelItem => item.Balance)</td> </tr> } </table> <hr /> <p class="text-center"> @Html.ActionLink("Edit this Loan Contract", "Edit", new { id = Model.LoanContractId }, htmlAttributes: new { @class = "wal-lead" }) :: @Html.ActionLink("Loans Contracts", "Index", null, htmlAttributes: new { @class = "wal-lead" }) </p>
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Watts' A Loan :: @ViewBag.Title</title> @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr") </head> <body> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container top-menu-holder"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> @Html.ActionLink("Watts' A Loan", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" }) </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li>@Html.ActionLink("Employees", "Index", "Employees")</li> <li>@Html.ActionLink("Loans Contracts", "Index", "LoansContracts")</li> <li>@Html.ActionLink("Payments", "Index", "Payments")</li> <li>@Html.ActionLink("About Watts' A Loan", "About", "Home")</li> <li>@Html.ActionLink("Contact Us", "Contact", "Home")</li> </ul> </div> </div> </div> <div class="container body-content"> @RenderBody() <hr /> <footer> <p class="text-center common-font yellow">© @DateTime.Now.Year - Watts' A Loan</p> </footer> </div> @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/bootstrap") @RenderSection("scripts", required: false) </body> </html>
@{ ViewBag.Title = "Home Page"; } <div class="jumbotron"> <h1 class="text-center">Watts' A Loan</h1> <p class="text-center"> <img src="~/Images/wal1.png" alt="Watts A Loan" width="650" height="200" /> </p> </div> <hr /> <div class="row"> <div class="col-md-9"> <dic class="row"> <div class="col-md-2"> <img src="~/Images/wal2.png" alt="Watts A Loan - Personal Loans" width="100" height="71" class="bordered" /> </div> <div class="col-md-10"> <h4 class="wheat">Personal Loans</h4> <p class="regular-text">Our most popular program is for personal loans, usually as cash, delivered directly from our office. The application process is very fast and easy. To start, access our loan application.</p> </div> </dic> <hr color="white" /> <dic class="row"> <div class="col-md-6"> <div class="row"> <div class="col-md-4"> <img src="~/Images/wal3.png" alt="Watts A Loan - Furniture Loans" width="100" height="75" class="bordered" /> </div> <div class="col-md-8"> <h4 class="wheat">Furniture Loans</h4> <p class="regular-text">Another one of our popular loan program is to assist customers in buying furniture.</p> </div> </div> </div> <div class="col-md-6"> <div class="row"> <div class="col-md-4"> <img src="~/Images/wal4.png" alt="Watts A Loan - Car Financing" width="100" height="75" class="bordered" /> </div> <div class="col-md-8"> <h4 class="wheat">Car Financing</h4> <p class="regular-text">Another one of our popular loan program is to assist customers in buying furniture.</p> </div> </div> </div> </dic> </div> <div class="col-md-3"> <div class="menu-box"> <ul> <li>Loan Application</li> <li>Loam Process</li> <li>Types of Loans</li> <li>Financial Aid</li> <li>Students Concerns</li> <li>Car Financing</li> <li>Musical Instruments</li> <li>Small Business Loan</li> <li>Documentation</li> <li>Newsletters</li> </ul> </div> </div> </div>
Employee # | First Name | Last Name | Employment Title |
293-747 | Catherine | Watts | Owner - General Manager |
836-486 | Thomas | Felton | Accounts Representative |
492-947 | Caroline | Wernick | Assistant Manager |
240-750 | Catherine | Donato | Accounts Representative |
804-685 | Melissa | Browns | Customer Accounts Representative |
429-374 | Denise | Leighton | Accounts Manager |
Date Allocated | Processed By | First Name | Last Name | Loan Type | Loan Amount | Interest Rate | Periods | Monthly Payment | Future Value | Interest Amount | Payment Start Date |
01/18/2018 | 429-374 | Joanne | Kennan | Personal Loan | 2500 | 14.65 | 36 | 99.97 | 3598.92 | 1098.92 | 02/01/2018 |
01/22/2018 | 492-947 | Stephanie | Haller | Boat Financing | 16500 | 12.25 | 60 | 443.44 | 26606.40 | 10106.40 | 03/01/2018 |
03/12/2018 | 429-374 | Annette | Vargas | Furniture Purchase | 2258.75 | 16.15 | 36 | 93.14 | 3353.11 | 1094.36 | 05/01/2018 |
03/12/2018 | 836-486 | Gérard | Maloney | Car Financing | 22748 | 10.25 | 60 | 573.44 | 34406.40 | 11658.40 | 05-01-2018 |
Loan Contract ID | Payment Date | Processed By | Payment Amount | Balance |
1 | 03/03/2018 | 429-374 | 99.97 | 3498.95 |
2 | 03/30/2018 | 492-947 | 443.44 | 26162.96 |
2 | 04/30/2018 | 836-486 | 443.44 | 25719.52 |
4 | 05/22/2018 | 836-486 | 573.44 | 33832.96 |
3 | 05/28/2018 | 429-374 | 93.14 | 3259.97 |
2 | 05/30/2018 | 429-374 | 443.44 | 25276.08 |
4 | 05/31/2018 | 492-947 | 573.44 | 33259.52 |
1 | 06/10/2018 | 240-750 | 199.94 | 3299.01 |
3 | 06/30/2018 | 240-750 | 93.14 | 3166.83 |
1 | 07/02/2018 | 429-374 | 99.97 | 3199.04 |
1 | 07/31/2018 | 836-486 | 99.97 | 3099.07 |
|
||
Home | Copyright © 2017-2019, FunctionX | Home |
|