public IHttpActionResult GetAllBySchoolSubjectId(int id) { 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 GetAllBySchoolSubjectId metod. Admin ID: {0}", adminId); var retVal1 = service.GetAllBySchoolSubjectId(id); 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 GetAllBySchoolSubjectIdAndTeacherId method. Teacher ID: {0}", teacherId); var retVal2 = service.GetAllBySchoolSubjectIdAndTeacherId(id, 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 GetAllBySchoolSubjectIdAndParentId method. Parent ID: {0}", parentId); var retVal3 = service.GetAllBySchoolSubjectIdAndParentId(id, 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 GetAllBySchoolSubjectIdAndStudentId. Student ID: {0}", userId); var retVal4 = service.GetAllBySchoolSubjectIdAndStudentId(id, 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)); } }