public void UpdateUserCreateVm(UserCreateVm model) { Email = model.Email; Name = model.Name; Role = model.Role; IsBlocked = model.IsBlocked; Branch = model.Branch; }
public ActionResult Register(UserCreateVm userCreateVm) { if (this.ModelState.IsValid) { var result = this.userService.CreateUser(userCreateVm); if (result.Success) { this.TempData["alert"] = "註冊成功,請登入以開始使用網站功能。"; return(this.RedirectToAction("Login")); } this.TempData["alert"] = result.Message.ReplaceContent(); } else { this.SetModelStateError(); } return(this.View(userCreateVm)); }
public JsonResult Edit(UserCreateVm model) { if (ModelState.IsValid) { try { string msg = string.Empty; var user = model.IsNew ? new User() : _db.Users.Find(model.UserId); if (user.Email != model.Email) { _userSrv.ValidateEmailUnique(model.Email); } user.UpdateUserCreateVm(model); if (model.IsNew) { _db.Users.Add(user); user.Password = RNGCryptoService.CreateHash("rh1234"); msg = "User Created"; } else { _db.Entry(user).State = System.Data.EntityState.Modified; msg = "User Modified"; } _db.SaveChanges(); _userSrv.AddUserLog(user.UserId, msg); } catch (SimpleException ex) { AddModelError(ex); } } return(GetErrorMsgJSON()); }