Razor Pages Application: Payroll Evaluation
Razor Pages Application: Payroll Evaluation
Introduction
Razor Pages is one of the techniques you can use to create an ASP.NET Core application. In this exercise, we will create a small application, add a webform to it, equip it with text boxes, and perform simple calculations.
Practical Learning: Creating the Application
html {
font-size: 14px;
}
@media (min-width: 768px) {
html {
font-size: 16px;
}
}
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
}
.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
color: var(--bs-secondary-color);
text-align: end;
}
.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
text-align: start;
}
.encloser { margin: auto;
width: 450px; }
.common-font { font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif }
@page @model IndexModel @{ ViewData["Title"] = "Payroll Evaluation"; string? strEmployeeName = string.Empty; string? strFirstName = string.Empty; string? strLastName = string.Empty; double hourlySalary = 0.00; string? strMonday = string.Empty; string? strTuesday = string.Empty; string? strWednesday = string.Empty; string? strThursday = string.Empty; string? strFriday = string.Empty; string? strRegularTime = string.Empty; string? strOverTime = string.Empty; string? strRegularPay = string.Empty; string? strOvertimePay = string.Empty; string? strNetPay = string.Empty; if (Request.HasFormContentType) { strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; hourlySalary = double.Parse(Request.Form["txtHourlySalary"]!); double monday = double.Parse(Request.Form["txtMonday"]!); double tuesday = double.Parse(Request.Form["txtTuesday"]!); double wednesday = double.Parse(Request.Form["txtWednesday"]!); double thursday = double.Parse(Request.Form["txtThursday"]!); double friday = double.Parse(Request.Form["txtFriday"]!); strEmployeeName = strFirstName + " " + strLastName; double totalTime = monday + tuesday + wednesday + thursday + friday; double ovtSalary = hourlySalary * 1.5; double regularTime = 0.00; double overTime = 0.00; double regularPay = 0.00; double overtimePay = 0.00; // If the employee worked below 40 hours, there is no overtime if (totalTime < 40) { regularTime = totalTime; regularPay = hourlySalary * totalTime; overTime = 0.00; overtimePay = 0.00; } // If the employee worked over 40 hours, calculate the overtime else // if (totalTime >= 40) { regularTime = 40; overTime = totalTime - 40; regularPay = hourlySalary * 40; overtimePay = overTime * ovtSalary; } var netPay = regularPay + overtimePay; strMonday = string.Format("{0:F}", monday); strTuesday = string.Format("{0:F}", tuesday); strWednesday = string.Format("{0:F}", wednesday); strThursday = string.Format("{0:F}", thursday); strFriday = string.Format("{0:F}", friday); strRegularTime = string.Format("{0:F}", regularTime); strOverTime = string.Format("{0:F}", overTime); strRegularPay = string.Format("{0:F}", regularPay); strOvertimePay = string.Format("{0:F}", overtimePay); strNetPay = string.Format("{0:F}", netPay); } } <h3 class="display-4 text-center fw-bold common-font">Payroll Evaluation</h3> <hr /> <form method="post" class="common-font encloser"> <div class="row mb-2"> <label for="txtFirstName" class="col-form-label col-sm-5 fw-bold">First Name:</label> <div class="col-sm-7"> <input id="txtFirstName" name="txtFirstName" class="form-control" value="@strFirstName" /> </div> </div> <div class="row mb-2"> <label for="txtLastName" class="fw-bold col-sm-5 col-form-label">Last Name:</label> <div class="col-sm-7"> <input id="txtLastName" name="txtLastName" class="form-control" value="@strLastName" /> </div> </div> <div class="row mb-2"> <label for="txtHourlySalary" class="fw-bold col-sm-5 col-form-label">Hourly Salary:</label> <div class="col-sm-7"> <input id="txtHourlySalary" name="txtHourlySalary" class="form-control" value="@hourlySalary" /> </div> </div> <div class="row mb-2"> <label for="txtMonday" class="fw-bold col-sm-5 col-form-label">Monday:</label> <div class="col-sm-7"> <input id="txtMonday" name="txtMonday" class="form-control" value="@strMonday" /> </div> </div> <div class="row mb-2"> <label for="txtTuesday" class="fw-bold col-sm-5 col-form-label">Tuesday:</label> <div class="col-sm-7"> <input id="txtTuesday" name="txtTuesday" class="form-control" value="@strTuesday" /> </div> </div> <div class="row mb-2"> <label for="txtWednesday" class="fw-bold col-sm-5 col-form-label">Wednesday:</label> <div class="col-sm-7"> <input id="txtWednesday" name="txtWednesday" class="form-control" value="@strWednesday" /> </div> </div> <div class="row mb-2"> <label for="txtThursday" class="fw-bold col-sm-5 col-form-label">Thursday:</label> <div class="col-sm-7"> <input id="txtThursday" name="txtThursday" class="form-control" value="@strThursday" /> </div> </div> <div class="row mb-2"> <label for="txtFriday" class="fw-bold col-sm-5 col-form-label">Friday:</label> <div class="col-sm-7"> <input id="txtFriday" name="txtFriday" class="form-control" value="@strFriday" /> </div> </div> <div class="row mb-2"> <label class="fw-bold col-sm-6 col-form-label"></label> <div class="col-sm-6"> <input type="submit" value="Calculate" id="btnCalculate" class="btn btn-primary" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtEmployeeName" class="fw-bold col-sm-5 col-form-label">Employee Name:</label> <div class="col-sm-7"> <input id="txtEmployeeName" name="txtEmployeeName" class="form-control" value="@strEmployeeName" /> </div> </div> <div class="row mb-2"> <label for="txtRegularTime" class="fw-bold col-sm-5 col-form-label">Regular Time:</label> <div class="col-sm-7"> <input id="txtRegularTime" class="form-control" value="@strRegularTime" /> </div> </div> <div class="row mb-2"> <label for="txtOverTime" class="fw-bold col-sm-5 col-form-label">Over Time:</label> <div class="col-sm-7"> <input id="txtOverTime" class="form-control" value="@strOverTime" /> </div> </div> <div class="row mb-2"> <label for="txtRegularPay" class="fw-bold col-sm-5 col-form-label">Regular Pay:</label> <div class="col-sm-7"> <input id="txtRegularPay" class="form-control" value="@strRegularPay" /> </div> </div> <div class="row mb-2"> <label for="txtOvertimePay" class="fw-bold col-sm-5 col-form-label">Overtime Pay:</label> <div class="col-sm-7"> <input id="txtOvertimePay" class="form-control" value="@strOvertimePay" /> </div> </div> <div class="row mb-2"> <label for="txtNetPay" class="fw-bold col-sm-5 col-form-label">Net Pay:</label> <div class="col-sm-7"> <input id="txtNetPay" class="form-control" value="@strNetPay" /> </div> </div> </form>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>@ViewData["Title"] - Payroll Evaluation</title> <script type="importmap"></script> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/PayrollEvaluation1.styles.css" asp-append-version="true" /> </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"> <a class="navbar-brand" asp-area="" asp-page="/Index">Payroll Evaluation</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-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="/Index">Home</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"> <p class="common-font text-center">© 2001-@DateTime.Today.Year - Payroll Evaluation - <a asp-area="" asp-page="/Privacy">Privacy</a></p> </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>
First Name: Michael Last Name: Carlock Hourly Salary: 28.46 Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 7.5
First Name: Catherine Last Name: Busbey Hourly Salary: 24.37 Monday: 9.5 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 8.5
|
|||
Home | Copyright © 2021-2025, FunctionX | Tuesday 17 December 2024, 11:28 | Home |
|