示例#1
0
        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));
        }
示例#2
0
        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);
        }
示例#3
0
        // 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));
        }
示例#4
0
        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);
        }