public IHttpActionResult Post(StudentRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var student = new Student { FirstName = model.FirstName, LastName = model.LastName, Age = model.Age, Number = model.Number }; this.data.Students.Add(student); this.data.Students.SaveChanges(); return this.Ok(student); }
public IHttpActionResult Put(int id, StudentRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var student = this.data.Students .All() .FirstOrDefault(s => s.Id == id); if (student == null) { return this.BadRequest("Student with id " + id + " does not exist!"); } student.FirstName = model.FirstName; student.LastName = model.LastName; student.Age = model.Age; student.Number = model.Number; this.data.Students.Update(student); this.data.Students.SaveChanges(); return this.Ok(model); }