示例#1
0
        public GetStudentResponse GetStudents()
        {
            GetStudentResponse response = new GetStudentResponse();

            response.Students = _dbContext.Student.ToList();
            return(response);
        }
        /// <summary>
        /// Used to get the studnet by their nickname
        /// </summary>
        /// <param name="nickname">The nickname of the student to be found</param>
        /// <returns>The student details</returns>
        public GetStudentResponse GetStudentByNickname(string nickname)
        {
            GetStudentResponse response = new GetStudentResponse();

            try
            {
                var dataLayer   = new StudentDatalayer();
                var nicknameDTO = dataLayer.GetStudentNicknameByNickname(nickname);

                if (nicknameDTO == null)
                {
                    response.Status = HttpStatusCode.NotFound;
                }
                else
                {
                    response.Nickname = nicknameDTO;
                    response.Status   = HttpStatusCode.OK;
                }
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to a get nickname");
                response.Status = HttpStatusCode.InternalServerError;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to get nickname"));
            }

            return(response);
        }