コード例 #1
0
        public IHttpActionResult GetGrades()
        {
            var userData = IdentityHelper.GetLoggedInUser(RequestContext);

            logger.Info("Get Grades by {@userData}", userData);

            logger.Info("Get grades for logged in user --- auto dispatch");

            var userInfo = Utilities.WebApi.IdentityHelper.FetchUserData(RequestContext);

            if (userInfo.UserId == null)
            {
                return(Unauthorized());
            }

            var userId = userInfo.UserId ?? 0;

            if (userInfo.IsAdmin)
            {
                return(Ok(gradesService.GetAllGrades()));
            }
            else if (userInfo.IsTeacher)
            {
                return(Ok(gradesService.GetAllGradesForTeacher(userId)));
            }
            else if (userInfo.IsStudent)
            {
                return(Ok(gradesService.GetAllGradesForStudent(userId)));
            }
            else if (userInfo.IsParent)
            {
                return(Ok(gradesService.GetAllGradesForParent(userId)));
            }
            else
            {
                logger.Error("Authenticated user with no role --- this should not happen");
                return(InternalServerError());
            }
        }