public IHttpActionResult Create(CourseModel course) { if (!this.ModelState.IsValid) { return this.BadRequest(ModelState); } var newStudent = new Course() { Description = course.Description, Name = course.Name, }; this.data.Courses.Add(newStudent); this.data.SaveChanges(); return Ok(course); }
public IHttpActionResult Create(CourseModel course) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var newCourse = new Course { Name = course.Name, Description = course.Description }; this.db.Courses.Add(newCourse); this.db.SaveChanges(); course.CourseId = newCourse.Id; return Ok(newCourse); }
public IHttpActionResult Update(Guid id, CourseModel student) { if (!this.ModelState.IsValid) { return this.BadRequest(ModelState); } var existingStudent = this.data .Courses .All() .FirstOrDefault(s => s.Id == id); if (existingStudent == null) { return this.BadRequest("No such student found!"); } existingStudent.Name = student.Name; existingStudent.Description = student.Description; this.data.SaveChanges(); return this.Ok(student); }