public ActionResult Update([DataSourceRequest] DataSourceRequest request, CourseGridViewModel course) { if (course != null && ModelState.IsValid) { var target = this.Data.Courses.All(new string[] { "Certificates" }).FirstOrDefault(c => c.Id == course.Id); if (target != null) { target.Title = course.Title; target.Description = course.Description; target.Lecturer = course.Lecturer; course.Certificates = target.Certificates.Select(c => c.Title).ToList(); this.Data.SaveChanges(); } } return(Json(new[] { course }.ToDataSourceResult(request, ModelState))); }
public ActionResult Create([DataSourceRequest] DataSourceRequest request, CourseGridViewModel course) { if ((course != null) && (ModelState.IsValid)) { var newCourse = new Course() { Title = course.Title, Lecturer = course.Lecturer, Description = course.Description, IsActive = course.IsActive }; this.Data.Courses.Add(newCourse); this.Data.SaveChanges(); course.Certificates = new List <string>(); course.Id = newCourse.Id; } return(Json(new[] { course }.ToDataSourceResult(request, ModelState))); }