public IActionResult Create() { ViewBag.employees = _employee.EmployeeList(); ViewBag.taxYears = _pay.GetAllTaxYears(); var model = new PayCreateViewModel(); return(View(model)); }
[ValidateAntiForgeryToken] // prevents cross site request forgery attack public async Task <IActionResult> Create(PayCreateViewModel model) { if (ModelState.IsValid == false) { ViewBag.employees = _employee.EmployeeList(); ViewBag.taxYears = _pay.GetAllTaxYears(); return(View()); } var payRecord = new PaymentRecord() { Id = model.Id, EmployeeId = model.EmployeeId, Employee = model.Employee, PayDate = model.PayDate, ContractedHours = model.ContractedHours, HourlyRate = model.HourlyRate, HoursWorked = model.HoursWorked, PayMonth = model.PayMonth, TaxYearId = model.TaxYearId, TaxCode = model.TaxCode, FullName = _employee.GetEmployeeById(model.EmployeeId).FullName, Nino = _employee.GetEmployeeById(model.EmployeeId).PersonalInfoEmployee.NSN, OverTimeHours = overtimeHours = _pay.OverTimeHours(model.HoursWorked, model.ContractedHours), ContractedEarnings = contractedEarnings = _pay.ContractualEarnings(model.HoursWorked, model.ContractedHours, model.HourlyRate), OverTimeEarnings = overtimeEarnings = _pay.OverTimeEarnings(_pay.OverTimeRate(model.HourlyRate), overtimeHours), TotalEarnings = totalEarnings = _pay.TotalEarnings(overtimeEarnings, contractedEarnings), StudentLoanRepay = studentLoanRepay = _deduction.StudentLoanRepay(model.EmployeeId, totalEarnings), UnionFee = unionFee = _deduction.UnionFees(model.EmployeeId), KiwiSaver = kiwiSave = _deduction.KiwiSaverDeduction(totalEarnings), Tax = taxCount = _deduction.TaxAmount(totalEarnings), TotalDeduction = totalDeduction = _pay.TotalDeductions(taxCount, kiwiSave, studentLoanRepay, unionFee), NetPayment = _pay.NetPay(totalEarnings, totalDeduction) }; await _pay.CreateAsync(payRecord); return(RedirectToAction(nameof(Index))); }