public IActionResult InitData() { for (int i = 0; i < 5; i++) { studentAppService.Register(new Application.ViewModel.StudentViewModel() { Id = Guid.NewGuid(), Name = $"TestName{i}", Email = $"aabbccdd0{i}@qq.com", BirthDate = DateTime.Now.AddMonths(0 - i) }); } return(Json("初始化数据成功")); }
public IActionResult Add(StudentViewModel input) { //_command = // new RegisterStudentCommand(input.Name, input.Email, input.Phone, input.BirthDate); //if (!_command.IsVaild()) //{ // _command.ValidationResult. // List<string> _err = new List<string>(); // foreach (var err in _command.ValidationResult.Errors) // { // _err.Add(err.ErrorMessage); // } // return Ok(new {_err }); //} _sevice.Register(input); var notify = _notify.GetNotify(); if (notify.Any()) { foreach (var item in notify) { //item.Value } } return(Ok()); }
public string Post(StudentViewModel studentViewModel) { if (!ModelState.IsValid) { string errorMsg = string.Empty; foreach (var onePire in ModelState) { var state = onePire.Value; errorMsg += ErrorString.CollectError(state.Errors.Select(r => r.ErrorMessage)); } return(errorMsg); } _service.Register(studentViewModel); #region /*RegisterStudentCommand registerStudentCommand = * new RegisterStudentCommand(studentViewModel.Name, * studentViewModel.Email, studentViewModel.BirthDate, * studentViewModel.Phone); * if (!registerStudentCommand.IsValid()) * { * return ErrorString.CollectError(registerStudentCommand.ValidationResult.Errors); * }*/ if (_notifications.HasNotifications()) { return(ErrorString.CollectError(_notifications.GetNotifications())); } #endregion return("success"); }
public ActionResult Create(StudentViewModel studentViewModel) { try { //_cache.Remove("ErrorData"); //ViewBag.ErrorData = null; // 视图模型验证 if (!ModelState.IsValid) { return(View(studentViewModel)); } #region 除命令验证 ////添加命令验证 //RegisterStudentCommand registerStudentCommand = new RegisterStudentCommand(studentViewModel.Name, studentViewModel.Email, studentViewModel.BirthDate, studentViewModel.Phone); ////如果命令无效,证明有错误 //if (!registerStudentCommand.IsValid()) //{ // List<string> errorInfo = new List<string>(); // //获取到错误,请思考这个Result从哪里来的 // foreach (var error in registerStudentCommand.ValidationResult.Errors) // { // errorInfo.Add(error.ErrorMessage); // } // //对错误进行记录,还需要抛给前台 // ViewBag.ErrorData = errorInfo; // return View(studentViewModel); //} #endregion // 执行添加方法 _studentAppService.Register(studentViewModel); //var errorData = _cache.Get("ErrorData"); //if (errorData == null) // 是否存在消息通知 if (!_notifications.HasNotifications()) { ViewBag.Sucesso = "Student Registered!"; } return(View(studentViewModel)); } catch (Exception e) { return(View(e.Message)); } }
public IActionResult Create(StudentViewModel studentViewModel) { try { if (!ModelState.IsValid) { return(View(studentViewModel)); } _studentAppService.Register(studentViewModel); ViewBag.success = "Student Registered!"; return(View(studentViewModel)); } catch (Exception e) { return(View(e.Message)); } }
public IActionResult Post([FromBody] Student student) { if (!ModelState.IsValid) { return(Response($"The student: {student.Name} cann't be created.")); } _studentAppService.Register(student); //INCREASE COURSE PROP SIZE _courseAppService.increaseCourseSize(student.CourseId); if (IsValidOperation()) { _logger.LogInformation($"Created student: {student.Name} "); } return(Ok($"The student: {student.Name} has been created.")); }
public ActionResult Create(StudentViewModel studentViewModel) { try { // 视图模型验证 if (!ModelState.IsValid) { return(View(studentViewModel)); } // 执行添加方法 _studentService.Register(studentViewModel); ViewBag.success = "Studen Registered"; return(View(studentViewModel)); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult Create(StudentViewModel studentViewModel) { try { if (!ModelState.IsValid) { return(View(studentViewModel)); } Guid guid = Guid.NewGuid(); studentViewModel.Id = guid; _studentAppService.Register(studentViewModel); ViewBag.Sucesso = "Student Registered!"; return(RedirectToAction(nameof(Index))); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult Create(StudentViewModel studentViewModel) { try { _cache.Remove("ErrorDate"); ViewBag.ErrorData = null; // 视图模型验证 if (!ModelState.IsValid) { return(View(studentViewModel)); } //添加命令验证,采用构造函数方法实例 RegisterStudentCommand registerStudentCommand = new RegisterStudentCommand(studentViewModel.Name, studentViewModel.Email, studentViewModel.BirthDate, studentViewModel.Phone); //如果命令无效,证明有错误 if (!registerStudentCommand.IsValid()) { List <string> errorInfo = new List <string>(); //获取到错误,请思考这个Result从哪里来的 foreach (var error in registerStudentCommand.ValidationResult.Errors) { errorInfo.Add(error.ErrorMessage); } //对错误进行记录,还需要抛给前台 ViewBag.ErrorData = errorInfo; return(View(studentViewModel)); } // 执行添加方法 _studentAppService.Register(studentViewModel); ViewBag.Sucesso = "Student Registered!"; return(View(studentViewModel)); } catch (Exception e) { return(View(e.Message)); } }
public ActionResult Create(StudentViewModel studentView) { try { if (!ModelState.IsValid) { return(View(studentView)); } _studentAppService.Register(studentView); ////对错误进行记录,还需要抛给前台 var notificacoes = _domainNotificationHandler.GetNotifications(); notificacoes.ForEach(c => ViewData.ModelState.AddModelError(string.Empty, c.Value)); return(View()); } catch (Exception ex) { throw; } //return View(studentView); }
public void Register(StudentViewModel StudentViewModel) { _studentAppService.Register(StudentViewModel); }