This is my code:
public IHttpActionResult PostNewStudent(StudentViewModel student)
{
if (!ModelState.IsValid)
return BadRequest("Invalid data.");
using (var ctx = new SchoolEntities())
{
ctx.Students.Add(new Student()
{
StudentId = student.Id,
FirstName = student.FirstName,
LastName = student.LastName
});
ctx.SaveChanges();
}
return Ok();
}
But when compiling it, I get this warning and it bursts. How should I organize my code so that I do not get this uncontrolled exception?