public IHttpActionResult UpdateStudent(int id, Student student) { studentsService = new StudentsService(); // check if student exists in db.students bool studentExistsInDb = studentsService.CheckIfStudentExistsById(id); if (!studentExistsInDb) { return(NotFound()); } // if exists update his name in db.students and db.unistudents Student updatedStudent = studentsService.UpdateStudent(id, student); if (updatedStudent == null) { return(BadRequest()); } studentToExposeService = new StudentToExposeService(); StudentToExpose studentToExpose = studentToExposeService.TrimStudent(student); return(Ok(studentToExpose)); }
// GET /api/students/id public IHttpActionResult GetStudent(int id) { if (id == 0) { return(NotFound()); } studentsService = new StudentsService(); Student student = studentsService.GetStudent(id); if (student == null) { return(NotFound()); } studentToExposeService = new StudentToExposeService(); StudentToExpose studentToExpose = studentToExposeService.TrimStudent(student); return(Ok(studentToExpose)); }