Search in sources :

Example 1 with UpdateException

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";
}
Also used : Department(amu.zhcet.data.department.Department) UpdateException(amu.zhcet.common.error.UpdateException)

Aggregations

UpdateException (amu.zhcet.common.error.UpdateException)1 Department (amu.zhcet.data.department.Department)1