public async Task <IActionResult> Details(Guid Id) { var employeeContractQuery = await _employeeContractServices.GetEmployeeContractsById(Id); if (employeeContractQuery == null) { return(NotFound()); } var model = new EmployeeContractsDetailViewModel { Id = employeeContractQuery.Id, TerminationDate = employeeContractQuery.TerminationDate == null ? string.Empty : DateTime.Parse(employeeContractQuery.TerminationDate.ToString()).ToString("yyyy-MM-dd"), StartDate = employeeContractQuery.StartDate == null ? string.Empty : DateTime.Parse(employeeContractQuery.StartDate.ToString()).ToString("yyyy-MM-dd"), MedicalCoverId = employeeContractQuery.MedicalCoverID ?? Guid.Empty, EmployeeId = employeeContractQuery.EmployeeID ?? Guid.Empty, ContactID = employeeContractQuery.ContractId ?? Guid.Empty, TerminationReason = employeeContractQuery.TerminationReason, WebAccess = employeeContractQuery.WebAccess, Mail = employeeContractQuery.Mail, Internet = employeeContractQuery.Internet, DailUpAccess = employeeContractQuery.DailUpAccess, Ability = employeeContractQuery.Ability, Finance = employeeContractQuery.Finance, ContractStatus = employeeContractQuery.ContractStatus, CDRInterConnection = employeeContractQuery.CDRInterConnection, AirtimeAllocation = employeeContractQuery.AirtimeAllocation }; await LoadSelectListsAsync(); return(View(model)); }
public async Task <IActionResult> Details(EmployeeContractsDetailViewModel formData) { try { if (ModelState.IsValid) { await _employeeContractServices.UpdateEmployeeContractAsync(new EmployeeContract { DateTimeModified = DateTimeOffset.Now, EmployeeID = formData.EmployeeId, ContractId = formData.ContactID, MedicalCoverID = formData.MedicalCoverId, TerminationReason = formData.TerminationReason, StartDate = DateTime.Parse(formData.StartDate), TerminationDate = DateTime.Parse(formData.TerminationDate), WebAccess = formData.WebAccess, Mail = formData.Mail, Internet = formData.Internet, DailUpAccess = formData.DailUpAccess, Ability = formData.Ability, Finance = formData.Finance, CDRInterConnection = formData.CDRInterConnection, AirtimeAllocation = formData.AirtimeAllocation, UserAccount = User.Identity.Name, ContractStatus = formData.ContractStatus, Id = formData.Id }); TempData["Message"] = "Changes saved successfully"; _logger.LogInformation($"Success: successfully updated employee contract record by user={@User.Identity.Name.Substring(4)}"); return(RedirectToAction("details", new { id = formData.Id })); } } catch (ApplicationException error) { _logger.LogError( error, $"FAIL: failed to update employee contract details. Internal Application Error.; user={@User.Identity.Name.Substring(4)}"); ModelState.AddModelError("Contract", $"Failed to update employee contract record. Contact IT ServiceDesk for support thank you."); } await LoadSelectListsAsync(); return(View(formData)); }