public InjuredPersonViewModel GetViewModel() { var accidentRecord = _accidentRecordService.GetByIdAndCompanyIdWithEmployeeInjured(_accidentRecordId, _companyId); var employees = _employeeService.GetAll(_companyId); var countries = _lookupService.GetCountries(); var othersInvolved = _lookupService.GetOthersInvolved(); var viewModel = new InjuredPersonViewModel(); viewModel.PersonInvolvedType = accidentRecord.PersonInvolved; viewModel.PersonInvolvedOtherDescription = accidentRecord.PersonInvolvedOtherDescription; viewModel.PersonInvolvedOtherDescriptionId = accidentRecord.PersonInvolvedOtherDescriptionId != null ? accidentRecord.PersonInvolvedOtherDescriptionId : null; viewModel.PersonInvolvedOtherDescriptionOther = accidentRecord.PersonInvolvedOtherDescriptionId == 9 ? accidentRecord.PersonInvolvedOtherDescription : null; viewModel.Employee = accidentRecord.EmployeeInjured != null ? accidentRecord.EmployeeInjured.FullName : null; viewModel.EmployeeId = accidentRecord.EmployeeInjured != null ? accidentRecord.EmployeeInjured.Id : (Guid?)null; viewModel.Employees = employees.Select(AutoCompleteViewModel.ForEmployee).AddDefaultOption(); viewModel.Forename = accidentRecord.NonEmployeeInjuredForename; viewModel.Surname = accidentRecord.NonEmployeeInjuredSurname; viewModel.AddressLine1 = accidentRecord.NonEmployeeInjuredAddress1; viewModel.AddressLine2 = accidentRecord.NonEmployeeInjuredAddress2; viewModel.AddressLine3 = accidentRecord.NonEmployeeInjuredAddress3; viewModel.County = accidentRecord.NonEmployeeInjuredCountyState; viewModel.Country = accidentRecord.NonEmployeeInjuredCountry != null ? accidentRecord.NonEmployeeInjuredCountry.Name : null; viewModel.CountryId = accidentRecord.NonEmployeeInjuredCountry != null ? accidentRecord.NonEmployeeInjuredCountry.Id : (int?)null; viewModel.Countries = AutoCompleteViewModel.ForCountries(countries); viewModel.Postcode = accidentRecord.NonEmployeeInjuredPostcode; viewModel.ContactNo = accidentRecord.NonEmployeeInjuredContactNumber; viewModel.Occupation = accidentRecord.NonEmployeeInjuredOccupation; viewModel.CompanyId = _companyId; viewModel.AccidentRecordId = _accidentRecordId; viewModel.NextStepsVisible = accidentRecord.NextStepsAvailable; viewModel.OthersInvolved = othersInvolved.Select(AutoCompleteViewModel.ForOthersInvolved).AddDefaultOption(); return viewModel; }
public InjuredPersonViewModel GetViewModel(InjuredPersonViewModel viewModel) { var employees = _employeeService.GetAll(_companyId); var countries = _lookupService.GetCountries(); var others = _lookupService.GetOthersInvolved(); viewModel.Employees = employees.Select(AutoCompleteViewModel.ForEmployee).AddDefaultOption(); viewModel.Countries = AutoCompleteViewModel.ForCountries(countries); viewModel.OthersInvolved = others.Select(AutoCompleteViewModel.ForOthersInvolved).AddDefaultOption(); return viewModel; }
public JsonResult SaveAndNext(InjuredPersonViewModel model) { if (ModelState.IsValid) { UpdateInjuredPerson(model); return Json(new {Success = true}); } else { return ModelStateErrorsAsJson(); } }
public ActionResult Save(InjuredPersonViewModel model) { if (!ModelState.IsValid) { var returnViewModel = _injuredPersonViewModelFactory .WithCompanyId(model.CompanyId) .WithAccidentRecordId(model.AccidentRecordId) .GetViewModel(model); ViewBag.NextStepsVisible = model.NextStepsVisible; return View("Index", returnViewModel); } UpdateInjuredPerson(model); TempData["Notice"] = "Details of injured person successfully updated"; return RedirectToAction("Index", new { accidentRecordId = model.AccidentRecordId, companyId = model.CompanyId }); //return View("Index", model); }
private void UpdateInjuredPerson(InjuredPersonViewModel model) { UpdateInjuredPersonRequest request = new UpdateInjuredPersonRequest() { AccidentRecordId = model.AccidentRecordId, CurrentUserId = CurrentUser.UserId, CompanyId = CurrentUser.GetUsersCompanyId(), PersonInvolved = model.PersonInvolvedType, PersonInvolvedOtherDescription = model.PersonInvolvedOtherDescription, PersonInvolvedOtherDescriptionId = model.PersonInvolvedOtherDescriptionId, PersonInvolvedOtherDescriptionOther = model.PersonInvolvedOtherDescriptionOther, EmployeeInjuredId = model.EmployeeId, NonEmployeeInjuredForename = model.Forename, NonEmployeeInjuredSurname = model.Surname, NonEmployeeInjuredAddress1 = model.AddressLine1, NonEmployeeInjuredAddress2 = model.AddressLine2, NonEmployeeInjuredAddress3 = model.AddressLine3, NonEmployeeInjuredCountyState = model.County, NonEmployeeInjuredCountry = model.CountryId, NonEmployeeInjuredPostcode = model.Postcode, NonEmployeeInjuredContactNumber = model.ContactNo, NonEmployeeInjuredOccupation = model.Occupation }; _accidentRecordService.UpdateInjuredPerson(request); }