public IHttpActionResult Create(CoursesOutputModel newCoursesInformation) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var newCourse = this.AddNewCourse(newCoursesInformation); newCoursesInformation.Id = newCourse.Id; return this.Ok(newCoursesInformation); }
public IHttpActionResult Update(CoursesOutputModel coursesUpdateInfo) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var course = this.studentData.Courses.FirstOrDefault(crs => crs.Id == coursesUpdateInfo.Id); if (course == null) { return this.BadRequest(NoSuchCourse); } course.Description = coursesUpdateInfo.Description; course.StartDate = coursesUpdateInfo.StartDate; course.EndDate = coursesUpdateInfo.EndDate; course.Name = coursesUpdateInfo.Name; this.studentData.SaveChanges(); coursesUpdateInfo.Id = course.Id; return this.Ok(coursesUpdateInfo); }
private Course AddNewCourse(CoursesOutputModel newCoursesInformation) { var newCourse = new Course { Description = newCoursesInformation.Description, StartDate = newCoursesInformation.StartDate, EndDate = newCoursesInformation.EndDate, Name = newCoursesInformation.Name, }; this.studentData.Courses.Add(newCourse); this.studentData.SaveChanges(); return newCourse; }