use of amu.zhcet.common.error.UpdateException in project zhcet-web by zhcet-amu.
the class CourseEditController method postCourse.
@PostMapping("/edit")
public String postCourse(@PathVariable Course course, @ModelAttribute("course") @Valid Course newCourse, BindingResult result, RedirectAttributes redirectAttributes) {
ErrorUtils.requireNonNullCourse(course);
Department department = course.getDepartment();
if (result.hasErrors()) {
redirectAttributes.addFlashAttribute("course", newCourse);
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.course", result);
} else {
try {
newCourse.setDepartment(department);
courseService.updateCourse(course, newCourse);
redirectAttributes.addFlashAttribute("course_success", "Course saved successfully!");
} catch (UpdateException e) {
log.warn("Course Save Error", e);
newCourse.setCode(course.getCode());
redirectAttributes.addFlashAttribute("course", newCourse);
redirectAttributes.addFlashAttribute("course_errors", e.getMessage());
}
}
return "redirect:/admin/department/courses/{course}/edit";
}
Aggregations