public async Task <IActionResult> Register_Teacher(RegisterTeacherViewmodel viewmodel) { if (!ModelState.IsValid) { throw new ValidatorException(); } if (!_SmsCodeValidatorService.Validate(viewmodel.Mobile, viewmodel.Code)) { throw new ValidatorException("验证码不正确"); } var teacher = await _Context.Teachers.AddAsync(new Models.Teacher { Introduce = viewmodel.Introduce, Mobile = viewmodel.Mobile, Name = viewmodel.Name, Password = MD5Builder.Builder32Hash(viewmodel.Password), Picture = viewmodel.Picture }); int result = await _Context.SaveChangesAsync(); if (result == 0) { throw new ValidatorException("该教师账号已存在"); } return(Json(teacher.Entity)); }
public async Task <IActionResult> Student_Update([FromBody] StudentUpdateViewModel viewModel) { var student = await _Context.Students.FirstOrDefaultAsync(v => v.ID == UserID); if (student == null) { throw new ValidatorException("不存在该用户"); } StudentUpdateIntegrationEvent @event = null; if (viewModel.Password != null) { student.Password = MD5Builder.Builder32Hash(viewModel.Password); } if (viewModel.Picture != null) { student.Picture = viewModel.Picture; } if (viewModel.NickName != null) { student.NickName = viewModel.NickName; @event = new StudentUpdateIntegrationEvent(UserID, viewModel.NickName); } using (var trans = _Context.Database.BeginTransaction(_CapPublisher, autoCommit: true)) { if (@event != null) { await _CapPublisher.PublishAsync("ELearn.UserCenter.StudentUpdate", @event); } } return(Json(true)); }
public async Task <IActionResult> Register_Student(RegisterStudentViewmodel viewmodel) { if (!ModelState.IsValid) { throw new ValidatorException(); } if (!_SmsCodeValidatorService.Validate(viewmodel.Mobile, viewmodel.Code)) { throw new ValidatorException("验证码不正确"); } var student = await _Context.Students.AddAsync(new Models.Student() { Mobile = viewmodel.Mobile, NickName = viewmodel.NickName, Password = MD5Builder.Builder32Hash(viewmodel.Password), Picture = viewmodel.Picture }); int result = await _Context.SaveChangesAsync(); if (result == 0) { throw new ValidatorException("用户已存在,无法注册"); } return(Json(student.Entity)); }
public async Task <IActionResult> Teacher_LoginByPassword(LoginByPasswordViewModel viewModel) { if (!ModelState.IsValid) { throw new ValidatorException(); } var teacher = await _Context.Teachers.AsNoTracking().Where(vn => vn.Mobile == viewModel.Mobile).FirstOrDefaultAsync(); if (teacher == null) { throw new ValidatorException("不存在该用户"); } if (teacher.Password != MD5Builder.Builder32Hash(viewModel.Password)) { throw new ValidatorException("登陆密码不正确"); } return(Json(teacher)); }