public IHttpActionResult PutStudent(int id, Student Student) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != Student.StudentId) { return BadRequest(); } db.Entry(Student).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostStudent(RegisterInputModel model) { Student student = new Student(); CustomUserAccount findacc = null; try { if (!ModelState.IsValid) { return BadRequest(ModelState); } var account = this.userAccountService.CreateAccount(model.Username, model.Password, model.Email); findacc = db.Users.Find(account.Key); var findCourse = db.Courses.Find(model.Course.CourseId); student.FirstName = model.FirstName; student.LastName = model.LastName; student.UserAccount = findacc; student.Course = findCourse; db.Students.Add(student); db.SaveChanges(); } catch (Exception ex) { if (findacc != null) db.Users.Remove(findacc); throw ex; } return Ok(student.StudentId); }