public IHttpActionResult Put(StudentRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var studentForUpdate = this.data.Students .SearchFor(c => c.FirstName == model.FirstName && c.LastName == model.LastName) .FirstOrDefault(); if (studentForUpdate == null) { return this.NotFound(); } studentForUpdate.Level = model.Level; studentForUpdate.AdditionalInformation.Address = model.Address; studentForUpdate.AdditionalInformation.Email = model.Email; this.data.Students.Update(studentForUpdate); this.data.SaveChanges(); return this.Ok(studentForUpdate); }
public IHttpActionResult Post(StudentRequestModel model) { if (model == null) { return this.BadRequest("Student is not set to un instance of object"); } var newStudent = new Student() { FirstName = model.FirstName, LastName = model.LastName, Level = model.Level, //AdditionalInformation = new StudentInfo(){Email = model.Email, Address = model.Address}, }; newStudent.AdditionalInformation.Email = model.Email; newStudent.AdditionalInformation.Address = model.Address; this.data.Students.Add(newStudent); this.data.SaveChanges(); return this.Ok(newStudent.StudentIdentification); }