public HttpResponseMessage Post(Student student) { if (string.IsNullOrEmpty(student.Firstname)) throw new HttpException(500, "missing Student's name"); try { this.context.Students.Add(student); this.context.SaveChanges(); } catch (Exception) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } return new HttpResponseMessage(HttpStatusCode.OK); }
public HttpResponseMessage Put(int id, Student student) { Student s = this.context.Students.Find(id); if (s != null) { s.Firstname = student.Firstname; s.Lastname = student.Lastname; this.context.SaveChanges(); return new HttpResponseMessage(HttpStatusCode.OK); } else { return new HttpResponseMessage(HttpStatusCode.NotFound); } }