コード例 #1
0
        public async Task <IActionResult> GetProfile()
        {
            var id = HttpContext.User.Claims
                     .FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
            var idGuid = Guid.Parse(id);

            var role = HttpContext.User.Claims
                       .FirstOrDefault(c => c.Type == ClaimTypes.Role).Value;

            if (role == "student")
            {
                var studentViewModel = await _repo.GetStudent(idGuid);

                if (studentViewModel.IsSuccess)
                {
                    return(View("StudentProfile", model: studentViewModel.Content));
                }

                return(RedirectToAction(
                           "GetLoginStudent",
                           routeValues: new { error = "Couldn't load student profile." }
                           ));
            }
            else if (role == "teacher")
            {
                var response = await _repo.GetTeacher(idGuid);

                if (response.IsSuccess)
                {
                    return(View("TeacherProfile", model: response.Content));
                }

                return(RedirectToAction(
                           "LoginTeacher",
                           routeValues: new { error = "Couldn't log in teacher" }
                           ));
            }

            return(RedirectToAction(
                       actionName: "Index",
                       controllerName: "Home"
                       ));
        }