}
@RequestMapping(value = "create", method = RequestMethod.POST)
public String createWorker(HealthWorkerDTO healthWorkerDTO, BindingResult result, Model model) {
if (result.hasErrors()) {
HealthPost healthPost = healthPostService.findById(healthWorkerDTO.getPostId());
model.addAttribute("healthPost", healthPost);
List<Gott> gotts = healthPost.getGotts();
model.addAttribute("gotts", gotts);
model.addAttribute("healthWorkerDTO", healthWorkerDTO);
return "/admin/healthpost/entries?pid=" + healthWorkerDTO.getPostId();
} else {
HealthExtensionWorker healthWorker = healthWorkerDTO.generateHealthWorker();
healthWorker.setPhoneNumber("+251" + healthWorker.getPhoneNumber());
HealthPost healthPost = healthPostService.findById(healthWorkerDTO.getPostId());
healthPostService.addHwToHp(healthWorker, healthPost);
return "redirect:/admin/healthpost/entries?pid=" + healthWorkerDTO.getPostId();
}
}