コード例 #1
0
        public async Task <IActionResult> ChangeToTeacher(ChangeToTeacherViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"用户不存在,UseId:{_userManager.GetUserId(User)}");
            }
            _teacherManager.ApplyToTeacherRole(user.UserName, model.RealName, model.School, model.ApplyReason);
            StatusMessage = "你的申请已提交成功,等待管理员审核。";
            return(RedirectToAction(nameof(ChangeToTeacher)));
        }
コード例 #2
0
        public async Task <IActionResult> ChangeToTeacher()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }
            if (User.IsInRole("teacher"))
            {
                throw new ApplicationException($"用户:{_userManager.GetUserName(User)},已经是老师了");
            }
            var model = new ChangeToTeacherViewModel()
            {
                StatusMessage = StatusMessage
            };

            return(View(model));
        }