public ActionResult EditCourse(CourseViewModel course) { if (ModelState.IsValid) { var c = _coursesProvider.GetCourse(course.Id); var template = _templatesProvider.GetTemplate(course.Template.Value); Employee manager = null; if (course.Keeper.HasValue) { manager = _employeesProvider.GetEmployee(course.Keeper.Value); } c.Name = course.Name; c.SetTemplate(template); _courseUpdater.Update(c); if ((c.Manager == null && course.Keeper.HasValue) || (c.Manager != null && c.Manager.Id != course.Keeper) || (c.Manager != null && c.Manager == null)) { _courseUpdater.SetManager(c, manager); } } return(RedirectToAction("Index")); }
public async Task <IActionResult> Update( int id, [FromBody] CourseRegistration registration) { //if(id == Guid.Empty) //{ // return NotFound(); //} if (registration == null) { return(BadRequest("Course registration not given")); } if (!ModelState.IsValid) { return(BadRequest("The given course registration is invalid")); } var result = await _courseUpdater.Update(id, registration); if (result.Successful()) { return(Ok(result.Body())); } return(BadRequest(result.GetAggregatedErrors())); }