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)); }
public StudentToExpose TrimStudent(Student student) { StudentToExpose studentToExpose = new StudentToExpose() { Id = student.ID, Name = student.Name, Email = student.Email, CourseId = student.CourseId, IsEnrolled = student.isEnrolled }; return(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)); }
public List <StudentToExpose> GetAllEnrolledStudents() { studentService = new StudentService(); List <StudentToExpose> studentsToExpose = new List <StudentToExpose>(); List <Student> allStudents = studentService.GetAllEnrolledStudents(); foreach (Student student in allStudents) { StudentToExpose studentToExpose = new StudentToExpose() { Id = student.ID, Name = student.Name, Email = student.Email, CourseId = student.CourseId, IsEnrolled = student.isEnrolled }; studentsToExpose.Add(studentToExpose); } return(studentsToExpose); }