public StudentModel GetById(int id)
 {
     var responseMsg = this.PerformOperationAndHandleExceptions(() =>
     {
         var result = new StudentModel();
         var db = new SchoolContext();
         var s = db.Students.Find(id);
         if (s != null)
         {
             result.Id = s.Id;
             result.FirstName = s.FirstName;
             result.LastName = s.LastName;
             result.Age = s.Age;
             result.Grade = s.Grade;
         }
         return result;
     });
     return responseMsg;
 }
        public void PostTest()
        {
            var student = new StudentModel()
            {
                FirstName = "Mimi",
                LastName = "Chervenopeyka",
                Age = 19,
                Grade = "12a"
            };

            var httpServer = new InMemoryHttpServer("http://localhost:4728/");
            var response = httpServer.CreatePostRequest("api/students", student);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.IsNotNull(response.Content);

            var contentString = response.Content.ReadAsStringAsync().Result;
            var model = JsonConvert.DeserializeObject<StudentModel>(contentString);

            Assert.IsTrue(model.Id > 0);
        }
        public HttpResponseMessage Post(StudentModel student)
        {
            var responseMsg = this.PerformOperationAndHandleExceptions(() =>
            {
                var newStudent = new Student()
                {
                    FirstName = student.FirstName,
                    LastName = student.LastName,
                    Age = student.Age,
                    Grade = student.Grade,
                    School = null,
                    SchoolId = null
                };
                var db = new SchoolContext();
                db.Students.Add(newStudent);
                db.SaveChanges();

                student.Id = newStudent.Id;
                var response = this.Request.CreateResponse(HttpStatusCode.Created, student);
                return response;
            });
            return responseMsg;
        }