ASP.NET Core Sample Application: Watts' A Loan
ASP.NET Core Sample Application: Watts' A Loan
Introduction
ASP.NET provides various options to create web-based applications. The latest one is ASP.NET Core with razor pages. To experiment with it, we will create an application named Watts' A Loan. It is for a small company that issues various types of loans.
Practical Learning: Introducing the Application
body { background-color: #370000; } .creame { color: wheat; } .yellow { color: orange; } .containment { margin: auto; width: 400px; } .top-menu-holder { width: 800px; margin: auto; } .form-horizontal { width: 400px; } .maint-title { color: sandybrown; font-weight: bold; } .texting { color: bisque; } .tbl-row { color: antiquewhite; } .tbl-head { color: yellow; font-weight: bold; } .form-control { border: solid 1px maroon; } .jumbotron { background-color: #370000; } .jumbotron h1 { color: yellow; font-weight: 600; text-shadow: 5px 5px black; } .menu-box { color: maroon; border-radius: 5px; background-color: burlywood; font-family: Garamond, 'Times New Roman', Georgia, serif; } .menu-box ul { list-style-type: none; } .border-bottom { border-bottom: 5px solid yellow !important; } .btn-primary { color: #800000; background-color: wheat; border-color: #000000; } .btn-primary:hover { color: #fff; background-color: orange; border-color: #800000; } .bg-white { background-color: #800000 !important; } a.text-dark:hover { color: #ffd800 !important; } a.text-dark:focus { color: antiquewhite !important; } .wal-lead { color: yellow; font-family: Georgia, Garamond, 'Times New Roman', serif; } a.wal-lead:hover { color: greenyellow; } a.wal-lead:focus { color: orange; } .wal-leader { color: orange; } a.wal-leader:hover { color: yellow; } a.wal-leader:focus { color: aqua; } .text-dark { color: antiquewhite !important; font-family: Garamond, 'Times New Roman', Georgia, serif; } .common-font { font-family: Georgia, Garamond, 'Times New Roman', serif; } .navbar-light .navbar-brand { color: antiquewhite; font-family: Garamond, 'Times New Roman', Georgia, serif; } .navbar-light .navbar-brand:hover { color: yellow } .navbar-light .navbar-brand:focus { color: aliceblue; } .navbar-light .navbar-brand { color: antiquewhite; font-family: Garamond, 'Times New Roman', Georgia, serif; }
Employees
The employees are the people who process transactions and perform other housekeeping chores for a company. To keep track of them, we will create a class and the necessary forms.
Practical Learning: Creating Employees
using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace WattsALoan2.Models { public class Employee { public Employee() { LoansContracts = new HashSet<LoanContract>(); Payments = new HashSet<Payment>(); } [Display(Name = "Employee ID")] public int EmployeeID { get; set; } [StringLength(10)] [Display(Name = "Employee #")] public string EmployeeNumber { get; set; } [StringLength(20)] [Display(Name = "First Name")] public string FirstName { get; set; } [StringLength(20)] [Display(Name = "Last Name")] public string LastName { get; set; } [StringLength(50)] [Display(Name = "Employee Title")] public string EmploymentTitle { get; set; } public string Identification { get { return EmployeeNumber + " - " + FirstName + " " + LastName + " (" + EmploymentTitle + ")"; } } public virtual ICollection<Payment> Payments { get; set; } public virtual ICollection<LoanContract> LoansContracts { get; set; } } }
using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace WattsALoan2.Models { public class LoanType { public LoanType() { LoansContracts = new HashSet<LoanContract>(); } [Display(Name = "LoanType ID")] public int LoanTypeID { get; set; } [StringLength(25)] [Display(Name = "Loan Name")] public string LoanName { get; set; } [MinLength(2)] [MaxLength(1024)] public string Description { get; set; } public virtual ICollection<LoanContract> LoansContracts { get; set; } } }
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace WattsALoan2.Models { public class LoanContract { public LoanContract() { Payments = new HashSet<Payment>(); } [Display(Name = "Loan Contract ID")] public int LoanContractID { get; set; } [Display(Name = "Loan #")] public int LoanNumber { get; set; } [DataType(DataType.Date)] [Display(Name = "Date Allocated")] public DateTime DateAllocated { get; set; } [Display(Name = "Processed By")] 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 int? LoanTypeID { get; set; } [Display(Name = "Loan Amount")] public decimal LoanAmount { get; set; } [Display(Name = "Interest Rate")] public decimal InterestRate { get; set; } public int Periods { get; set; } [Display(Name = "Interest Amount")] public decimal InterestAmount { get; set; } [Display(Name = "Future Value")] public decimal FutureValue { get; set; } [Display(Name = "Monthly Payment")] public decimal MonthlyPayment { get; set; } [DataType(DataType.Date)] [Display(Name = "Payment Start Date")] public DateTime PaymentStartDate { get; set; } [Display(Name = "Current Balance")] public decimal CurrentBalance { get; set; } public string LoanDetails { get { return "Loan # " + LoanNumber.ToString() + " in the amount of " + LoanAmount.ToString("C") + " for " + CustomerFirstName + " " + CustomerLastName + " paid at " + MonthlyPayment.ToString("F") + "/month; current balance: $" + CurrentBalance.ToString("C"); } } public virtual Employee Employee { get; set; } public virtual LoanType LoanType { get; set; } public virtual ICollection<Payment> Payments { get; set; } } }
using System; using System.ComponentModel.DataAnnotations; namespace WattsALoan2.Models { public class Payment { [Display(Name = "Payment ID")] public int PaymentID { get; set; } [Display(Name = "Receipt #")] public int ReceiptNumber { get; set; } [DataType(DataType.Date)] [Display(Name = "Payment Date")] public DateTime PaymentDate { get; set; } [Display(Name = "Processed By")] public int? EmployeeID { get; set; } [Display(Name = "Loan Contract")] public int? LoanContractID { get; set; } [Display(Name = "Payment Amount")] public decimal PaymentAmount { get; set; } public virtual Employee Employee { get; set; } public virtual LoanContract LoanContract { get; set; } } }
@page @model WattsALoan2.Pages.Employees.CreateModel @{ ViewData["Title"] = "Create Employee"; } <h1 class="bold creme common-font text-center">Employment Application</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <label asp-for="Employee.EmployeeNumber" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.EmployeeNumber" class="form-control" /> <span asp-validation-for="Employee.EmployeeNumber" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Employee.FirstName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.FirstName" class="form-control" /> <span asp-validation-for="Employee.FirstName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Employee.LastName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.LastName" class="form-control" /> <span asp-validation-for="Employee.LastName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Employee.EmploymentTitle" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.EmploymentTitle" class="form-control" /> <span asp-validation-for="Employee.EmploymentTitle" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="Index" class="wal-lead col-md-5">Display Employees</a> <div class="col-md-7 text-center"> <input type="submit" value="Save Employee Record" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.Employees.DeleteModel @{ ViewData["Title"] = "Delete Employee"; } <h1 class="bold creme common-font text-center">Delete Employee Record</h1> <hr color="yellow" /> <h3 class="creme text-center common-font">Are you sure you want to delete this employee record?</h3> <div class="containment"> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.EmployeeID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.EmployeeID) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.EmployeeNumber) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.EmployeeNumber) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.FirstName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.FirstName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.LastName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.LastName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.EmploymentTitle) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.EmploymentTitle) </div> </div> <hr color="yellow" /> <form method="post"> <a asp-page="./Index" class="text-center wal-lead">Staff Members</a> :: <input type="hidden" asp-for="Employee.EmployeeID" /> <input type="submit" value="Delete Employee" class="btn btn-primary" /> </form> </div>
@page @model WattsALoan2.Pages.Employees.DetailsModel @{ ViewData["Title"] = "Employee Details"; } <h1 class="bold creme common-font text-center">Employee Details</h1> <hr color="yellow" /> <div class="containment"> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.EmployeeID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.EmployeeID) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.EmployeeNumber) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.EmployeeNumber) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.FirstName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.FirstName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.LastName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.LastName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Employee.EmploymentTitle) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Employee.EmploymentTitle) </div> </div> <hr color="yellow" /> <div> <a asp-page="./Index" class="text-center wal-lead">Employees</a> :: <a asp-page="./Edit" asp-route-id="@Model.Employee.EmployeeID" class="wal-lead">Edit Employee</a> </div> </div>
@page @model WattsALoan2.Pages.Employees.EditModel @{ ViewData["Title"] = "Edit Employee"; } <h1 class="bold creme common-font text-center">Edit/Update Employee</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <input type="hidden" asp-for="Employee.EmployeeID" /> <label asp-for="Employee.EmployeeNumber" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.EmployeeNumber" class="form-control" /> <span asp-validation-for="Employee.EmployeeNumber" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Employee.FirstName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.FirstName" class="form-control" /> <span asp-validation-for="Employee.FirstName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Employee.LastName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.LastName" class="form-control" /> <span asp-validation-for="Employee.LastName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Employee.EmploymentTitle" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Employee.EmploymentTitle" class="form-control" /> <span asp-validation-for="Employee.EmploymentTitle" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="./Index" class="wal-lead col-md-5">Display Employees</a> <div class="col-md-7 text-center"> <input type="submit" value="Save the Update" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.Employees.IndexModel @{ ViewData["Title"] = "Employees"; } <h1 class="bold maint-title common-font text-center">Employees</h1> <table class="table common-font"> <thead> <tr class="tbl-head"> <th class="text-center">@Html.DisplayNameFor(model => model.Employee[0].EmployeeID)</th> <th>@Html.DisplayNameFor(model => model.Employee[0].EmployeeNumber)</th> <th>@Html.DisplayNameFor(model => model.Employee[0].FirstName)</th> <th>@Html.DisplayNameFor(model => model.Employee[0].LastName)</th> <th>@Html.DisplayNameFor(model => model.Employee[0].EmploymentTitle)</th> <th><a asp-page="Create" class="wal-leader">Hire Employee</a></th> </tr> </thead> <tbody> @foreach (var item in Model.Employee) { <tr class="tbl-row"> <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> <a asp-page="./Edit" asp-route-id="@item.EmployeeID" class="wal-lead">Edit</a> :: <a asp-page="./Details" asp-route-id="@item.EmployeeID" class="wal-lead">Details</a> :: <a asp-page="./Delete" asp-route-id="@item.EmployeeID" class="wal-lead">Delete</a> </td> </tr> } </tbody> </table>
Loans Types
A financial instituation, such as the one for our application, provides various types of loans. Because companies vary, instead of providing a fixed list of types of loans, we will let the employees of the company create the names of loans.
Practical Learning: Managing Loans Types
@page @model WattsALoan2.Pages.LoansTypes.CreateModel @{ ViewData["Title"] = "Create Loan Type"; } <h1 class="bold creme common-font text-center">Create a Loan Type</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <label asp-for="LoanType.LoanName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanType.LoanName" class="form-control" /> <span asp-validation-for="LoanType.LoanName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanType.Description" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <textarea asp-for="LoanType.Description" class="form-control"></textarea> <span asp-validation-for="LoanType.Description" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="Index" class="col-md-5 wal-lead">Display Loans Types</a> <div class="col-md-7 text-center"> <input type="submit" value="Save Loan Type" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.LoansTypes.DeleteModel @{ ViewData["Title"] = "Delete Loan Type"; } <h1 class="bold creme common-font text-center">Delete Loan Type</h1> <hr color="yellow" /> <h3 class="creme text-center common-font">Are you sure you want to delete this loan type?</h3> <div class="containment"> <div class="form-group row common-font creme"> @Html.DisplayNameFor(model => model.LoanType.LoanTypeID) <div class="col-md-7"> @Html.DisplayFor(model => model.LoanType.LoanTypeID) </div> </div> <div class="form-group row common-font creme"> @Html.DisplayNameFor(model => model.LoanType.LoanName) <div class="col-md-7"> @Html.DisplayFor(model => model.LoanType.LoanName) </div> </div> <div class="form-group row common-font creme"> @Html.DisplayNameFor(model => model.LoanType.Description) <div class="col-md-7"> @Html.DisplayFor(model => model.LoanType.Description) </div> </div> <hr color="yellow" /> <form method="post"> <input type="hidden" asp-for="LoanType.LoanTypeID" /> <a asp-page="./Index" class="wal-lead">Loans Types</a> :: <input type="submit" value="Delete Loan Type" class="btn btn-primary" /> </form> </div>
@page @model WattsALoan2.Pages.LoansTypes.DetailsModel @{ ViewData["Title"] = "Loan Type Details"; } <h1 class="bold creme common-font text-center">Loan Type Details</h1> <hr color="yellow" /> <div class="containment"> <div class="form-group row common-font creme"> @Html.DisplayNameFor(model => model.LoanType.LoanTypeID) <div class="col-md-7"> @Html.DisplayFor(model => model.LoanType.LoanTypeID) </div> </div> <div class="form-group row common-font creme"> @Html.DisplayNameFor(model => model.LoanType.LoanName) <div class="col-md-7"> @Html.DisplayFor(model => model.LoanType.LoanName) </div> </div> <div class="form-group row common-font creme"> @Html.DisplayNameFor(model => model.LoanType.Description) <div class="col-md-7"> @Html.DisplayFor(model => model.LoanType.Description) </div> </div> <hr color="yellow" /> <div> <a asp-page="./Index" class="wal-lead">Loans Types</a> :: <a asp-page="./Edit" asp-route-id="@Model.LoanType.LoanTypeID" class="wal-lead">Edit this Loan Type</a> </div> </div>
@page @model WattsALoan2.Pages.LoansTypes.EditModel @{ ViewData["Title"] = "Edit Loan Type"; } <h1 class="bold creme common-font text-center">Edit/Update Loan Type</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <input type="hidden" asp-for="LoanType.LoanTypeID" /> <label asp-for="LoanType.LoanName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanType.LoanName" class="form-control" /> <span asp-validation-for="LoanType.LoanName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanType.Description" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <textarea asp-for="LoanType.Description" class="form-control"></textarea> <span asp-validation-for="LoanType.Description" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="./Index" class="col-md-5 wal-lead">Loans Types</a> <div class="col-md-7 text-center"> <input type="submit" value="Update Loan Type" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.LoansTypes.IndexModel @{ ViewData["Title"] = "Loans Types"; } <h1 class="bold common-font maint-title text-center">Loans Types</h1> <table class="table common-font"> <thead> <tr class="tbl-head"> <th class="text-center">@Html.DisplayNameFor(model => model.LoanType[0].LoanTypeID)</th> <th>@Html.DisplayNameFor(model => model.LoanType[0].LoanName)</th> <th>@Html.DisplayNameFor(model => model.LoanType[0].Description)</th> <th><a asp-page="Create" class="wal-leader">Create Loan Type</a></th> </tr> </thead> <tbody> @foreach (var item in Model.LoanType) { <tr class="tbl-row"> <td class="text-center">@Html.DisplayFor(modelItem => item.LoanTypeID)</td> <td>@Html.DisplayFor(modelItem => item.LoanName)</td> <td>@Html.DisplayFor(modelItem => item.Description)</td> <td> <a asp-page="./Edit" asp-route-id="@item.LoanTypeID" class="wal-lead">Edit</a> :: <a asp-page="./Details" asp-route-id="@item.LoanTypeID" class="wal-lead">Details</a> :: <a asp-page="./Delete" asp-route-id="@item.LoanTypeID" class="wal-lead">Delete</a> </td> </tr> } </tbody> </table>
Loans Contracts
The company of our application issues various types of loans to many customers. This includes people and businesses. To get a loan, a person or a company must apply for it. For our application, we will create a loan from which an application can be applied for. Then we will create other forms to manage the loans records.
Practical Learning: Managing Loans Contracts
using WattsALoan2.Models; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WattsALoan2.Pages.LoansContracts { public class CreateModel : PageModel { private readonly WattsALoan2.Data.WattsALoan2Context _context; public CreateModel(WattsALoan2.Data.WattsALoan2Context context) { _context = context; } public IActionResult OnGet() { ViewData["EmployeeID"] = new SelectList(_context.Employee, "EmployeeID", "Identification"); ViewData["LoanTypeID"] = new SelectList(_context.LoanType, "LoanTypeID", "LoanName"); return Page(); } [BindProperty] public LoanContract LoanContract { get; set; } // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return Page(); } _context.LoanContract.Add(LoanContract); await _context.SaveChangesAsync(); return RedirectToPage("./Index"); } } }
@page @model WattsALoan2.Pages.LoansContracts.CreateModel @{ ViewData["Title"] = "Create Loan Contract"; } <h1 class="bold creme common-font text-center">Process Loan Contract</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <label asp-for="LoanContract.LoanNumber" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.LoanNumber" class="form-control" /> <span asp-validation-for="LoanContract.LoanNumber" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.DateAllocated" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.DateAllocated" class="form-control" /> <span asp-validation-for="LoanContract.DateAllocated" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.EmployeeID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="LoanContract.EmployeeID" class="form-control" asp-items="ViewBag.EmployeeID"></select> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.CustomerFirstName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.CustomerFirstName" class="form-control" /> <span asp-validation-for="LoanContract.CustomerFirstName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.CustomerLastName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.CustomerLastName" class="form-control" /> <span asp-validation-for="LoanContract.CustomerLastName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.LoanTypeID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="LoanContract.LoanTypeID" class="form-control" asp-items="ViewBag.LoanTypeID"></select> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.LoanAmount" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.LoanAmount" class="form-control" /> <span asp-validation-for="LoanContract.LoanAmount" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.InterestRate" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.InterestRate" class="form-control" /> <span asp-validation-for="LoanContract.InterestRate" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.Periods" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.Periods" class="form-control" /> <span asp-validation-for="LoanContract.Periods" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.InterestAmount" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.InterestAmount" class="form-control" /> <span asp-validation-for="LoanContract.InterestAmount" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.FutureValue" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.FutureValue" class="form-control" /> <span asp-validation-for="LoanContract.FutureValue" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.MonthlyPayment" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.MonthlyPayment" class="form-control" /> <span asp-validation-for="LoanContract.MonthlyPayment" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.PaymentStartDate" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.PaymentStartDate" class="form-control" /> <span asp-validation-for="LoanContract.PaymentStartDate" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.CurrentBalance" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.CurrentBalance" class="form-control" /> <span asp-validation-for="LoanContract.CurrentBalance" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="Index" class="wal-lead col-md-5">Loans Contracts</a> <div class="col-md-7 text-center"> <input type="submit" value="Save Loan Contract" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.LoansContracts.DeleteModel @{ ViewData["Title"] = "Delete Loan Contract"; } <h1 class="bold creme common-font text-center">Delete Loan Contract</h1> <hr color="yellow" /> <h3 class="creme text-center common-font">Are you sure you want to delete this loan contract?</h3> <div class="containment"> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanContractID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanContractID) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanNumber) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanNumber) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.DateAllocated) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.DateAllocated) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> <label>Processed By</label> </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.Employee.Identification) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.CustomerFirstName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.CustomerFirstName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.CustomerLastName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.CustomerLastName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanType) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanType.LoanName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanAmount) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanAmount) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.InterestRate) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.InterestRate) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.Periods) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.Periods) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.InterestAmount) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.InterestAmount) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.FutureValue) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.FutureValue) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.MonthlyPayment) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.MonthlyPayment) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.PaymentStartDate) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.PaymentStartDate) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.CurrentBalance) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.CurrentBalance) </div> </div> <hr color="yellow" /> <form method="post"> <input type="hidden" asp-for="LoanContract.LoanContractID" /> <a asp-page="./Index" class="wal-lead">Loans Contracts</a> :: <input type="submit" value="Delete Loan Contract" class="btn btn-primary" /> </form> </div>
@page @model WattsALoan2.Pages.LoansContracts.DetailsModel @{ ViewData["Title"] = "Loan Contract Details"; } <h1 class="bold creme common-font text-center">Loan Contract Details</h1> <hr color="yellow" /> <div class="containment"> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanContractID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanContractID) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanNumber) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanNumber) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.DateAllocated) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.DateAllocated) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.EmployeeID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.Employee.Identification) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.CustomerFirstName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.CustomerFirstName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.CustomerLastName) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.CustomerLastName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanType) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanType.LoanName) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.LoanAmount) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.LoanAmount) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.InterestRate) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.InterestRate) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.Periods) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.Periods) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.InterestAmount) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.InterestAmount) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.FutureValue) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.FutureValue) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.MonthlyPayment) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.MonthlyPayment) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.PaymentStartDate) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.PaymentStartDate) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.LoanContract.CurrentBalance) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.LoanContract.CurrentBalance) </div> </div> <hr color="yellow" /> <div class="form-group"> <a asp-page="./Index" class="wal-lead">Loans Contracts</a> :: <a asp-page="./Edit" asp-route-id="@Model.LoanContract.LoanContractID" class="wal-lead">Edit/update this loan contract</a> </div> </div>
using System.Linq; using WattsALoan2.Models; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WattsALoan2.Pages.LoansContracts { public class EditModel : PageModel { private readonly WattsALoan2.Data.WattsALoan2Context _context; public EditModel(WattsALoan2.Data.WattsALoan2Context context) { _context = context; } [BindProperty] public LoanContract LoanContract { get; set; } public async Task<IActionResult> OnGetAsync(int? id) { if (id == null) { return NotFound(); } LoanContract = await _context.LoanContract .Include(l => l.Employee) .Include(l => l.LoanType).FirstOrDefaultAsync(m => m.LoanContractID == id); if (LoanContract == null) { return NotFound(); } ViewData["EmployeeID"] = new SelectList(_context.Employee, "EmployeeID", "Identification"); ViewData["LoanTypeID"] = new SelectList(_context.LoanType, "LoanTypeID", "LoanName"); return Page(); } // To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return Page(); } _context.Attach(LoanContract).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoanContractExists(LoanContract.LoanContractID)) { return NotFound(); } else { throw; } } return RedirectToPage("./Index"); } private bool LoanContractExists(int id) { return _context.LoanContract.Any(e => e.LoanContractID == id); } } }
@page @model WattsALoan2.Pages.LoansContracts.EditModel @{ ViewData["Title"] = "Edit Loan Contract"; } <h1 class="bold creme common-font text-center">Edit/Update Loan Contract</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <input type="hidden" asp-for="LoanContract.LoanContractID" /> <label asp-for="LoanContract.LoanNumber" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.LoanNumber" class="form-control" /> <span asp-validation-for="LoanContract.LoanNumber" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.DateAllocated" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.DateAllocated" class="form-control" /> <span asp-validation-for="LoanContract.DateAllocated" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.EmployeeID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="LoanContract.EmployeeID" class="form-control" asp-items="ViewBag.EmployeeID"></select> <span asp-validation-for="LoanContract.EmployeeID" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.CustomerFirstName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.CustomerFirstName" class="form-control" /> <span asp-validation-for="LoanContract.CustomerFirstName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.CustomerLastName" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.CustomerLastName" class="form-control" /> <span asp-validation-for="LoanContract.CustomerLastName" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.LoanTypeID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="LoanContract.LoanTypeID" class="form-control" asp-items="ViewBag.LoanTypeID"></select> <span asp-validation-for="LoanContract.LoanTypeID" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.LoanAmount" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.LoanAmount" class="form-control" /> <span asp-validation-for="LoanContract.LoanAmount" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.InterestRate" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.InterestRate" class="form-control" /> <span asp-validation-for="LoanContract.InterestRate" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.Periods" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.Periods" class="form-control" /> <span asp-validation-for="LoanContract.Periods" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.InterestAmount" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.InterestAmount" class="form-control" /> <span asp-validation-for="LoanContract.InterestAmount" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.FutureValue" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.FutureValue" class="form-control" /> <span asp-validation-for="LoanContract.FutureValue" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.MonthlyPayment" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.MonthlyPayment" class="form-control" /> <span asp-validation-for="LoanContract.MonthlyPayment" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.PaymentStartDate" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.PaymentStartDate" class="form-control" /> <span asp-validation-for="LoanContract.PaymentStartDate" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="LoanContract.CurrentBalance" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="LoanContract.CurrentBalance" class="form-control" /> <span asp-validation-for="LoanContract.CurrentBalance" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="./Index" class="wal-lead col-md-5">Loans Contracts</a> <div class="col-md-7 text-center"> <input type="submit" value="Update Loan Contract" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.LoansContracts.IndexModel @{ ViewData["Title"] = "Loans Contracts"; } <h1 class="bold common-font text-center maint-title">Loans Contracts</h1> <table class="table common-font"> <thead> <tr class="tbl-head"> <th class="text-center">@Html.DisplayNameFor(model => model.LoanContract[0].LoanContractID)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].LoanNumber)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].DateAllocated)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].EmployeeID)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].CustomerFirstName)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].CustomerLastName)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].LoanType)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].LoanAmount)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].InterestRate)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].Periods)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].InterestAmount)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].FutureValue)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].MonthlyPayment)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].PaymentStartDate)</th> <th>@Html.DisplayNameFor(model => model.LoanContract[0].CurrentBalance)</th> <th><a asp-page="Create" class="wal-leader">Process Loan Contract</a></th> </tr> </thead> <tbody> @foreach (var item in Model.LoanContract) { <tr class="tbl-row"> <td class="text-center">@Html.DisplayFor(modelItem => item.LoanContractID)</td> <td>@Html.DisplayFor(modelItem => item.LoanNumber)</td> <td>@Html.DisplayFor(modelItem => item.DateAllocated)</td> <td>@Html.DisplayFor(modelItem => item.Employee.Identification)</td> <td>@Html.DisplayFor(modelItem => item.CustomerFirstName)</td> <td>@Html.DisplayFor(modelItem => item.CustomerLastName)</td> <td>@Html.DisplayFor(modelItem => item.LoanType.LoanName)</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.InterestAmount)</td> <td>@Html.DisplayFor(modelItem => item.FutureValue)</td> <td>@Html.DisplayFor(modelItem => item.MonthlyPayment)</td> <td>@Html.DisplayFor(modelItem => item.PaymentStartDate)</td> <td>@Html.DisplayFor(modelItem => item.CurrentBalance)</td> <td> <a asp-page="./Edit" asp-route-id="@item.LoanContractID" class="wal-lead">Edit</a> :: <a asp-page="./Details" asp-route-id="@item.LoanContractID" class="wal-lead">Details</a> :: <a asp-page="./Delete" asp-route-id="@item.LoanContractID" class="wal-lead">Delete</a> </td> </tr> } </tbody> </table>
Loans Payments
People and businesses that have received a loan must pay it. This means that we must create forms that employees can use to process the necessary payments.
Practical Learning: Managing Loans Contracts
using WattsALoan2.Models; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WattsALoan2.Pages.Payments { public class CreateModel : PageModel { private readonly WattsALoan2.Data.WattsALoan2Context _context; public CreateModel(WattsALoan2.Data.WattsALoan2Context context) { _context = context; } public IActionResult OnGet() { ViewData["EmployeeID"] = new SelectList(_context.Employee, "EmployeeID", "Identification"); ViewData["LoanContractID"] = new SelectList(_context.LoanContract, "LoanContractID", "LoanDetails"); return Page(); } [BindProperty] public Payment Payment { get; set; } // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return Page(); } /* When a payment has been made, we need to change the balance of the loan. * To do that, check each loan contract, looking for a loan contract that * uses corresponds to the one whose payment was made her. */ foreach(LoanContract lc in _context.LoanContract) { /* To find the loan contract of the current payment, compare the * LoanContractID of this payment (the foreign key) and each of the * LoanContractID of the LoanContrats table (the primary key). * If you find that loan contract, ... */ if(lc.LoanContractID == Payment.LoanContractID) { // ... subtract the current payment from the balance in the LoanContracts table. lc.CurrentBalance = lc.CurrentBalance - Payment.PaymentAmount; // In the SaveChangesAsync() call, the records will be saved. } } _context.Payment.Add(Payment); await _context.SaveChangesAsync(); return RedirectToPage("./Index"); } } }
@page @model WattsALoan2.Pages.Payments.CreateModel @{ ViewData["Title"] = "Create Payment"; } <h1 class="bold creme common-font text-center">Make Loan Payment</h1> <hr color="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="form-group row common-font"> <label asp-for="Payment.ReceiptNumber" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Payment.ReceiptNumber" class="form-control" /> <span asp-validation-for="Payment.ReceiptNumber" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Payment.PaymentDate" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Payment.PaymentDate" class="form-control" /> <span asp-validation-for="Payment.PaymentDate" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Payment.EmployeeID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="Payment.EmployeeID" class="form-control" asp-items="ViewBag.EmployeeID"></select> </div> </div> <div class="form-group row common-font"> <label asp-for="Payment.LoanContractID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="Payment.LoanContractID" class="form-control" asp-items="ViewBag.LoanContractID"></select> </div> </div> <div class="form-group row common-font"> <label asp-for="Payment.PaymentAmount" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Payment.PaymentAmount" class="form-control" /> <span asp-validation-for="Payment.PaymentAmount" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="form-group row"> <a asp-page="Index" class="col-md-5 wal-lead">Loans Payments</a> <div class="text-center col-md-7"> <input type="submit" value="Save Loan Payment" class="btn btn-primary" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.Payments.DeleteModel @{ ViewData["Title"] = "Delete Payment"; } <h1 class="bold creme common-font text-center">Delete Loan Payment</h1> <hr color="yellow" /> <h3 class="creme text-center common-font">Are you sure you want to delete this payment?</h3> <div class="containment"> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.PaymentID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.PaymentID) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.ReceiptNumber) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.ReceiptNumber) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.PaymentDate) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.PaymentDate) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.EmployeeID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.Employee.Identification) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.LoanContractID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.LoanContract.LoanDetails) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.PaymentAmount) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.PaymentAmount) </div> </div> <hr color="yellow" /> <form method="post"> <input type="hidden" asp-for="Payment.PaymentID" /> <a asp-page="./Index" class="text-center wal-lead">Loans Payments</a> :: <input type="submit" value="Delete Payment" class="btn btn-warning" /> </form> </div>
@page @model WattsALoan2.Pages.Payments.DetailsModel @{ ViewData["Title"] = "Payment Details"; } <h1 class="bold creme common-font text-center">Payment Details</h1> <hr color="yellow" /> <div class="containment"> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.PaymentID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.PaymentID) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.ReceiptNumber) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.ReceiptNumber) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.PaymentDate) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.PaymentDate) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.EmployeeID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.Employee.Identification) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.LoanContractID) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.LoanContract.LoanDetails) </div> </div> <div class="form-group row common-font creme"> <div class="control-label col-md-5"> @Html.DisplayNameFor(model => model.Payment.PaymentAmount) </div> <div class="col-md-7"> @Html.DisplayFor(model => model.Payment.PaymentAmount) </div> </div> <hr color="yellow" /> <div> <a asp-page="./Index" class="text-center wal-lead">Loans Payments</a> :: <a asp-page="./Edit" asp-route-id="@Model.Payment.PaymentID" class="wal-lead">Edit this Payment</a> </div> </div>
using System.Linq; using WattsALoan2.Models; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.RazorPages; namespace WattsALoan2.Pages.Payments { public class EditModel : PageModel { private readonly WattsALoan2.Data.WattsALoan2Context _context; public EditModel(WattsALoan2.Data.WattsALoan2Context context) { _context = context; } [BindProperty] public Payment Payment { get; set; } public async Task<IActionResult> OnGetAsync(int? id) { if (id == null) { return NotFound(); } Payment = await _context.Payment .Include(p => p.Employee) .Include(p => p.LoanContract).FirstOrDefaultAsync(m => m.PaymentID == id); if (Payment == null) { return NotFound(); } ViewData["EmployeeID"] = new SelectList(_context.Employee, "EmployeeID", "Identification"); ViewData["LoanContractID"] = new SelectList(_context.LoanContract, "LoanContractID", "LoanDetails"); return Page(); } // To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task<IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return Page(); } _context.Attach(Payment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PaymentExists(Payment.PaymentID)) { return NotFound(); } else { throw; } } return RedirectToPage("./Index"); } private bool PaymentExists(int id) { return _context.Payment.Any(e => e.PaymentID == id); } } }
@page @model WattsALoan2.Pages.Payments.EditModel @{ ViewData["Title"] = "Edit Payment"; } <h1 class="bold creme common-font text-center">Edit/Update Loan Payment</h1> <hr class="yellow" /> <form method="post" class="containment"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="row form-group common-font"> <input type="hidden" asp-for="Payment.PaymentID" /> <label asp-for="Payment.ReceiptNumber" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Payment.ReceiptNumber" class="form-control" /> <span asp-validation-for="Payment.ReceiptNumber" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Payment.PaymentDate" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Payment.PaymentDate" class="form-control" /> <span asp-validation-for="Payment.PaymentDate" class="text-danger"></span> </div> </div> <div class="form-group common-font row"> <label asp-for="Payment.EmployeeID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="Payment.EmployeeID" class="form-control" asp-items="ViewBag.EmployeeID"></select> <span asp-validation-for="Payment.EmployeeID" class="text-danger"></span> </div> </div> <div class="row form-group common-font"> <label asp-for="Payment.LoanContractID" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <select asp-for="Payment.LoanContractID" class="form-control" asp-items="ViewBag.LoanContractID"></select> <span asp-validation-for="Payment.LoanContractID" class="text-danger"></span> </div> </div> <div class="form-group row common-font"> <label asp-for="Payment.PaymentAmount" class="control-label col-md-5 creme"></label> <div class="col-md-7"> <input asp-for="Payment.PaymentAmount" class="form-control" /> <span asp-validation-for="Payment.PaymentAmount" class="text-danger"></span> </div> </div> <hr color="yellow" /> <div class="row form-group"> <div class="col-md-5"> <a asp-page="./Index" class="wal-lead">Loans Payments</a> </div> <div class="col-md-5 text-center"> <input type="submit" value="Update Loan Payment" class="btn btn-warning" /> </div> </div> </form> @section Scripts { @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} }
@page @model WattsALoan2.Pages.Payments.IndexModel @{ ViewData["Title"] = "Loans Payments"; } <h1 class="maint-title bold common-font text-center">Loans Payments</h1> <table class="table common-font"> <thead> <tr class="tbl-head"> <th class="text-center">@Html.DisplayNameFor(model => model.Payment[0].PaymentID)</th> <th>@Html.DisplayNameFor(model => model.Payment[0].ReceiptNumber)</th> <th>@Html.DisplayNameFor(model => model.Payment[0].PaymentDate)</th> <th>@Html.DisplayNameFor(model => model.Payment[0].Employee.EmployeeID)</th> <th>@Html.DisplayNameFor(model => model.Payment[0].LoanContract.LoanNumber)</th> <th>@Html.DisplayNameFor(model => model.Payment[0].PaymentAmount)</th> <th><a asp-page="Create" class="wal-leader">Process Loan Payment</a></th> </tr> </thead> <tbody> @foreach (var item in Model.Payment) { <tr class="tbl-row"> <td class="text-center">@Html.DisplayFor(modelItem => item.PaymentID)</td> <td>@Html.DisplayFor(modelItem => item.ReceiptNumber)</td> <td>@Html.DisplayFor(modelItem => item.PaymentDate)</td> <td>@Html.DisplayFor(modelItem => item.Employee.Identification)</td> <td>@Html.DisplayFor(modelItem => item.LoanContract.LoanDetails)</td> <td>@Html.DisplayFor(modelItem => item.PaymentAmount)</td> <td> <a asp-page="./Edit" asp-route-id="@item.PaymentID" class="wal-lead">Edit</a> :: <a asp-page="./Details" asp-route-id="@item.PaymentID" class="wal-lead">Details</a> :: <a asp-page="./Delete" asp-route-id="@item.PaymentID" class="wal-lead">Delete</a> </td> </tr> } </tbody> </table>
Creating a Database
To use the Code First From Database option of the entity framework, in your project, add an ADO.NET Entity Data Model to your Models folder. In the wizard, select the Code First From Database option and follow the wizard.
Practical Learning: Creating a Database
Add-Migration InitialCreate
Update-Database
Finalizing the Application
A regular web-based application should have a home page. From that page, most objects of the application can be accessed. In an ASP.NET application, both MVC or .NET Core, you usually use a _Layout,cshtml and an Index.cshtml documents to create a home page.
Practical Learning: Finalizing the Application
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>@ViewData["Title"] - Watts' A Loan</title> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="~/css/site.css" /> <link rel="stylesheet" href="~/css/WattsALoan.css" /> </head> <body> <header> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <div class="container top-menu-holder"> <a class="navbar-brand" asp-area="" asp-page="/Index">Watts' A Loan</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> <ul class="navbar-nav flex-grow-1"> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/Employees/Index">Employees</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/LoansContracts/Index">Loans Contracts</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/Payments/Index">Payments</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/LoansTypes/Index">Loans Types</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/Index">About Us</a> </li> <li class="nav-item"> <a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a> </li> </ul> </div> </div> </nav> </header> <div class="container"> <main role="main" class="pb-3"> @RenderBody() </main> </div> <footer class="border-top footer text-muted"> <div class="container text-center"> <span class="creme common-font">© @DateTime.Today.Year - Watts' A Loan -</span> <a asp-area="" asp-page="/Privacy" class="wal-lead">Privacy</a> </div> </footer> <script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> @await RenderSectionAsync("Scripts", required: false) </body> </html>
@page @model IndexModel @{ ViewData["Title"] = "Watts' A Loan"; } <div class="jumbotron"> <h1 class="text-center common-font">Watts' A Loan</h1> <p class="text-center"> <img src="~/images/wal1.png" alt="Watts A Loan" width="650" height="200" /> </p> </div> <hr color="yellow" /> <div class="row"> <div class="col-md-9"> <div class="row common-font"> <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="creame">Personal Loans</h4> <p class="texting">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> </div> <hr color="white" /> <div class="row"> <div class="col-md-6"> <div class="row common-font"> <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>Furniture Loans</h4> <p class="texting">Another one of our popular loan programs is to assist customers in buying furniture.</p> </div> </div> </div> <div class="col-md-6"> <div class="row common-font"> <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>Car Financing</h4> <p class="texting">Another one of our popular loan program is to assist customers in buying furniture.</p> </div> </div> </div> </div> </div> <div class="col-md-3"> <div class="menu-box"> <ul> <li>Loan Application</li> <li>Loan 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>
Testing the Application
After creating the necessary documents, you can execute the application to access and test its objects.
Practical Learning: Creating a Database
Employee # | First Name | Last Name | Employee 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 |
INSERT Employees VALUES(N'293-747', N'Catherine', N'Watts', N'Owner'), (N'836-486', N'Thomas', N'Felton', N'Accounts Representative'), (N'492-947', N'Caroline', N'Wernick', N'Assistant Manager'), (N'240-750', N'Catherine', N'Donato', N'Accounts Representative'), (N'804-685', N'Melissa', N'Browns', N'Customer Accounts Representative'), (N'429-374', N'Denise', N'Leighton', N'Accounts Manager'); GO
Loan Type | Description |
Personal Cash | This type of loan is provided as cash to a customer. |
Car Financing | We partner with various car dealers in our metropolitan area. Customers typically apply for car loans from dealerships. If/When a loan has been approved, we issue the necessary amount. |
Boat Financing | Like cars, boats are financed through boat dealers, repair shops, or manufacturers. A customer can apply for a loan from one of those businesses or directly from our office. |
Furniture Purchase | We provide low interest loans for people who need to purchase some furniture but may not have all the necessary cash. Customers may apply for a loan to finance furniture from a retail store. |
Musical Instrument | Among the types of loans that fit our interests are those from a regular musical instrument such as a piano to a complete recording studio. |
INSERT INTO LoanTypes(LoanName, [Description]) VALUES(N'Personal Cash', N'This type of loan is provided as cash to a customer.'), (N'Car Financing', N'We partner with various car dealers in our metropolitan area. Customers typically apply for car loans from dealerships. If/When a loan has been approved, we issue the necessary amount.'), (N'Boat Financing', N'Like cars, boats are financed through boat dealers, repair shops, or manufacturers. A customer can apply for a loan from one of those businesses or directly from our office.'), (N'Furniture Purchase', N'We provide low interest loans for people who need to purchase some furniture but may not have all the necessary cash. Customers may apply for a loan to finance furniture from a retail store.'), (N'Musical Instrument', N'Among the types of loans that fit our interests are those from a regular musical instrument such as a piano to a complete recording studio.'); GO
Loan Number: 100001 Date Allocated: January 18, 2021 Employee #: 429-374 First Name: Joanne Last Name: Kennan Loan Type: Personal Cash Loan Amount: 2500 Interest Rate: 14.65 Periods: 36 Interest Amount: 1,483.51 Future Value: 3,983.51 Monthly Payment: 87.44 Current Balance: 3,983.51 Payment Start Date: March 1st, 2021
Loan Number: 100002 Date Allocated: February 22, 2021 Employee #: 492-947 First Name: Stephen Last Name: Haller Loan Type: Boat Financing Loan Amount: 46500 Interest Rate: 4.95 Periods: 60 Interest Amount: 13,027.79 Future Value: 59,527.79 Monthly Payment: 876.45 Payment Start Date: March 1st, 2021 Current Balance: 59,527.79
Loan Number: 100003 Date Allocated: March 12, 2021 Employee #: 429-374 First Name: Annette Last Name: Vargas Loan Type: Furniture Purchase Loan Amount: 2258.75 Interest Rate: 17.35 Periods: 36 Interest Amount: 1,528.29 Future Value: 3,787.04 Monthly Payment: 80.92 Payment Start Date: May 1st, 2021 Current Balance: 3,787.04
Loan Number: 100004 Date Allocated: March 12, 2021 Employee #: 836-486 First Name: Gérard Last Name: Haloney Loan Type: Car Financing Loan Amount: 22748 Interest Rate: 10.25 Periods: 60 Interest Amount: 15,146.30 Future Value: 37,894.30 Monthly Payment: 486.13 Payment Start Date: May 1st, 2021 Current Balance: 37,894.30
Receipt Number: 385970 Payment Date: March 03, 2021 Processed By: 429-374 Loan Contract: 100001 Payment Amount: 87.44
Receipt Number: 953746 Payment Date: March 30, 2021 Processed By: 492-947 Loan Contract: 100002 Payment Amount: 876.45
|
||
Home | Copyright © 2017-2025, FunctionX | Home |
|