Beispiel #1
0
        public IHttpActionResult GetAllByGradingDateRange([FromUri] DateTime minDate, [FromUri] DateTime maxDate)
        {
            string role = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == ClaimTypes.Role).Value;

            try
            {
                switch (role)
                {
                case "admin":
                    string adminId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
                    logger.Info("Calling admin access level GradesService GetAllByGradingDateRange metod. Admin ID: {0}", adminId);
                    var retVal1 = service.GetAllByGradingDateRange(minDate, maxDate);
                    logger.Info("Returning ok to browser.");
                    return(Ok(retVal1));

                case "teacher":
                    string teacherId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
                    logger.Info("Calling teacher access level GradesService GetAllByGradignDateRangeAndTeacherId method. Teacher ID: {0}", teacherId);
                    var retVal2 = service.GetAllByGradignDateRangeAndTeacherId(minDate, maxDate, teacherId);
                    logger.Info("Returning ok to browser.");
                    return(Ok(retVal2));

                case "parent":
                    string parentId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
                    logger.Info("Calling parent access level GradesService GetAllByGradingDateRangeAndParentId method. Parent ID: {0}", parentId);
                    var retVal3 = service.GetAllByGradingDateRangeAndParentId(minDate, maxDate, parentId);
                    logger.Info("Returning ok to browser.");
                    return(Ok(retVal3));

                case "student":
                    string userId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;
                    logger.Info("Caling student access level GradesService method GetAllByGradingDateRangeAndStudentId. Student ID: {0}", userId);
                    var retVal4 = service.GetAllByGradingDateRangeAndStudentId(minDate, maxDate, userId);
                    logger.Info("Returning ok to browser.");
                    return(Ok(retVal4));

                default:
                    logger.Warn("BadRequest. There is no method for this role! {0}", role);
                    return(BadRequest());
                }
            }
            catch (Exception e)
            {
                logger.Warn("Caught exception with message {0}. Returning bad request.", e.Message);
                return(BadRequest(e.Message));
            }
        }