public IHttpActionResult GetAll() { 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 GetAll metod. Admin ID: {0}", adminId); var retVal1 = service.GetAll(); 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 GetAllByTeacherId method. Teacher ID: {0}", teacherId); var retVal2 = service.GetAllByTeacherId(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 GetAllByParentId method. Parent ID: {0}", parentId); var retVal3 = service.GetAllByParentId(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 GetAllByStudentId. Student ID: {0}", userId); var retVal4 = service.GetAllByStudentId(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)); } }