public void TestAdd() { var account = "user_" + DateTime.Now.ToString("yyyy_MM_dd HH:mm:ss"); Console.WriteLine(account); var app = _autofacServiceProvider.GetService <UserManagerApp>(); var newuser = new UpdateUserReq { Account = account, Name = account, OrganizationIds = "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b,543a9fcf-4770-4fd9-865f-030e562be238", }; app.AddOrUpdate(newuser); app.AddOrUpdate(new UpdateUserReq { Id = newuser.Id, Password = "******", Account = account, Name = "新名字", OrganizationIds = "08f41bf6-4388-4b1e-bd3e-2ff538b44b1b", }); }
void UpdateUser_NO_Service(User oldUser) { UpdateUserReq req = new UpdateUserReq(); UpdateUserService svc = new UpdateUserService(); req.BusinessData.UsersBE = oldUser; req.BusinessData.UsersBE.FirstName = oldUser.FirstName + "_updated"; req.BusinessData.UsersBE.LastName = oldUser.LastName + "_updated"; req.BusinessData.UsersBE.ModifiedByUserId = 12; req.BusinessData.UsersBE.ModifiedDate = System.DateTime.Now; req.BusinessData.UsersBE.Email = oldUser.Email + ".ar"; req.BusinessData.PasswordOnly = false; try { UpdateUserRes res = svc.Execute(req); } catch (Exception ex) { base.StrExceptionMessage = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex); } Assert.AreEqual <String>(base.StrExceptionMessage, String.Empty, base.StrExceptionMessage); }
void UpdateUser_cpass_NO_Service(User oldUser) { UpdateUserReq req = new UpdateUserReq(); UpdateUserService svc = new UpdateUserService(); req.BusinessData.ChangePassword = new ChangePassword(); req.BusinessData.ChangePassword.New = "11111"; req.BusinessData.ChangePassword.Old = "66666"; req.BusinessData.UsersBE = oldUser; req.BusinessData.PasswordOnly = true; try { UpdateUserRes res = svc.Execute(req); } catch (Exception ex) { base.StrExceptionMessage = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex); } Assert.AreEqual <String>(base.StrExceptionMessage, String.Empty, base.StrExceptionMessage); }
/// <summary> /// 更新用户信息 /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override async Task <BoolReply> UpdateUser(UpdateUserReq request, ServerCallContext context) { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } var user = await userManager.FindByIdAsync(request.UserId.ToString()).ConfigureAwait(false); if (user == null) { return(null); } user.SecurityStamp = Guid.NewGuid().ToString(); user.Name = request.Name; user.PhoneNumber = request.PhoneNumber; user.Email = request.Email; user.Sex = byte.Parse(request.Sex.ToString()); user.Desc = request.Desc; var result = await userManager.UpdateAsync(user).ConfigureAwait(false); return(new BoolReply { Value = result.Succeeded }); }
public string UpdateSonInfo(UpdateUserReq req) { var id = Convert.ToInt32(Session["userId"]); var userId = Convert.ToInt32(req.userId); var r = AllFunc.Instance.UpdateSonInfo(req, userId, id); return(JsonConvert.SerializeObject(r)); }
public void AddOrUpdate(UpdateUserReq request) { request.ValidationEntity(u => new { u.Account, u.Name, u.OrganizationIds }); if (string.IsNullOrEmpty(request.OrganizationIds)) { throw new Exception("请为用户分配机构"); } User requser = request; requser.CreateId = _auth.GetCurrentUser().User.Id; UnitWork.ExecuteWithTransaction(() => { if (string.IsNullOrEmpty(request.Id)) { if (UnitWork.Any <User>(u => u.Account == request.Account)) { throw new Exception("用户账号已存在"); } if (string.IsNullOrEmpty(requser.Password)) { requser.Password = requser.Account; //如果客户端没提供密码,默认密码同账号 } requser.CreateTime = DateTime.Now; UnitWork.Add(requser); request.Id = requser.Id; //要把保存后的ID存入view } else { UnitWork.Update <User>(u => u.Id == request.Id, u => new User { Account = requser.Account, BizCode = requser.BizCode, Name = requser.Name, Sex = requser.Sex, Status = requser.Status }); if (!string.IsNullOrEmpty(requser.Password)) //密码为空的时候,不做修改 { UnitWork.Update <User>(u => u.Id == request.Id, u => new User { Password = requser.Password }); } } UnitWork.Save(); string[] orgIds = request.OrganizationIds.Split(',').ToArray(); _revelanceApp.DeleteBy(Define.USERORG, requser.Id); _revelanceApp.Assign(Define.USERORG, orgIds.ToLookup(u => requser.Id)); }); }
public void OnUpdateUserReq(UpdateUserReq packet) { var user = packet.User; Sql.Instance.UpdateUser(user); if (packet.ForceDisconnect) { _server.DisconnectUser(user.Id); } }
public string AddOrUpdate(UpdateUserReq request) { try { _app.AddOrUpdate(request); } catch (Exception ex) { Result.Code = 500; Result.Message = ex.InnerException?.Message ?? ex.Message; } return(JsonHelper.Instance.Serialize(Result)); }
public async Task <IActionResult> Update(long id, [FromBody] UpdateUserReq req) { var cmd = new UpdateUserCmd(req, id, HttpContext.UserId().Value); var updated = await userRepository.Update(cmd); var user = await userRepository.WithId(id); if (updated) { return(Ok(user)); } else { return(BadRequest()); } }
protected override void ProcessRecord() { var result = CurrentUcClient.Instance.Client.Execute(client => { var updateRequest = new UpdateUserReq { ItemElementName = ItemChoiceType6.userid, Item = Username }; bool hasChange = false; if (AssociatedDevices != null) { hasChange = true; updateRequest.associatedDevices = AssociatedDevices; } if (hasChange) { var res = client.updateUser(updateRequest); return(res.@return); } else { throw new Exception("No change has been specified"); } }); var user = CurrentUcClient.Instance.Client.Execute(client => { var res = client.getUser(new GetUserReq { ItemElementName = ItemChoiceType100.userid, Item = Username }); return(res.@return); }); if (user.Exception != null) { throw user.Exception; } else { WriteObject(user.Value.user); } }
public Response <string> AddOrUpdate(UpdateUserReq obj) { var result = new Response <string>(); try { _app.AddOrUpdate(obj); result.Result = obj.Id; //返回ID } catch (Exception ex) { result.Code = 500; result.Message = ex.InnerException?.Message ?? ex.Message; } return(result); }
/// <summary> /// Cambiar el password de un usuario /// </summary> /// <param name="pUserName">Nombre de usuario</param> /// <param name="pPassword">Password viejo</param> /// <param name="pNewPassword">Password Nuevo</param> internal static void UserChangePassword(String pUserName, String pPassword, String pNewPassword) { UpdateUserReq req = new UpdateUserReq(); req.BusinessData.PasswordOnly = true; req.BusinessData.UsersBE = new User(); req.BusinessData.UsersBE.UserName = pUserName; req.BusinessData.RolList = null; req.BusinessData.ChangePassword = new ChangePassword(); req.BusinessData.ChangePassword.New = pNewPassword; req.BusinessData.ChangePassword.Old = pPassword; UpdateUserRes res = req.ExecuteService <UpdateUserReq, UpdateUserRes>(WrapperSecurityProvider, req); if (res.Error != null) { throw Fwk.Exceptions.ExceptionHelper.ProcessException(res.Error); } }
public async Task <TResponse <bool> > Update(int userId, UpdateUserReq user) { try { var canUpdate = await CanUpdate(user); if (canUpdate.IsSuccess) { var result = await _writeRepository.ExecuteAsync(SqlQuery.USER_UPDATE, new { user.Id, user.Email, user.Name, user.Phone, UserUpdated = userId, DateUpdated = DateTime.Now }); if (result != null) { if (result.IsSuccess) { if (result.Data == 0) { return(await Fail <bool>($"Update USER {user.Id} is failure")); } return(await Ok(true)); } return(await Fail <bool>(result.Message)); } return(await Fail <bool>($"Update USER {user.Id} is failure")); } return(await Fail <bool>(canUpdate.Message)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
/// <summary> /// Actualiza un usuario /// </summary> /// <param name="pUser">User</param> internal static void UpdateUser(User pUser, RolList pRolList) { UpdateUserReq req = new UpdateUserReq(); req.BusinessData.UsersBE = pUser; req.BusinessData.RolList = pRolList; req.BusinessData.PasswordOnly = false; if (!string.IsNullOrEmpty(pUser.Password)) { req.BusinessData.ChangePassword = new ChangePassword(); req.BusinessData.ChangePassword.New = pUser.Password; req.BusinessData.ChangePassword.Old = string.Empty; } UpdateUserRes res = req.ExecuteService <UpdateUserReq, UpdateUserRes>(WrapperSecurityProvider, req); if (res.Error != null) { throw Fwk.Exceptions.ExceptionHelper.ProcessException(res.Error); } }
/// <summary> /// 修改用户信息 /// </summary> /// <param name="req">用户信息</param> /// <param name="oper">操作者信息</param> public BaseItemRes <bool> UpdateUser(UpdateUserReq req, OperatorInfo oper) { //判断用户是否存在 var user = this.userDAL.GetUser(req.LoginName); if (user == null) { return(AccHelper.FailItemRes(AccConfig.Msg.UserNotExist, false)); } user.UserName = req.UserName; user.Gender = req.Gender; user.Birthday = req.Birthday; user.MobilePhone = req.MobilePhone; user.Email = req.Email; this.SetUpdateFields(user, oper); //更新数据库 this.userDAL.UpdateUser(user); return(AccHelper.OkItemRes(true)); }
public async Task <TResponse <bool> > CanUpdate(UpdateUserReq user) { try { var users = await GetById(user.Id); if (users != null) { if (users.IsSuccess) { return(await Ok(true)); } return(await Fail <bool>(users.Message)); } return(await Ok(true)); } catch (Exception exception) { return(await Fail <bool>(exception)); } }
public BaseItemRes <bool> UpdateUser([FromBody] UpdateUserReq req) { return(this.userBLL.UpdateUser(req, this.CurUser)); }
/// <summary> /// Cambiar el password de un usuario /// </summary> /// <param name="pUserName">Nombre de usuario</param> /// <param name="pPassword">Password viejo</param> /// <param name="pNewPassword">Password Nuevo</param> internal static void UserChangePassword(String pUserName, String pPassword, String pNewPassword) { UpdateUserReq req = new UpdateUserReq(); req.BusinessData.PasswordOnly = true; req.BusinessData.UsersBE = new User(); req.BusinessData.UsersBE.UserName = pUserName; req.BusinessData.RolList = null; req.BusinessData.ChangePassword = new ChangePassword(); req.BusinessData.ChangePassword.New = pNewPassword; req.BusinessData.ChangePassword.Old = pPassword; UpdateUserRes res = req.ExecuteService<UpdateUserReq, UpdateUserRes>(WrapperSecurityProvider,req); if (res.Error != null) { throw Fwk.Exceptions.ExceptionHelper.ProcessException(res.Error); } }
/// <summary> /// Actualiza un usuario /// </summary> /// <param name="pUser">User</param> internal static void UpdateUser(User pUser, RolList pRolList) { UpdateUserReq req = new UpdateUserReq(); req.BusinessData.UsersBE = pUser; req.BusinessData.RolList = pRolList; req.BusinessData.PasswordOnly = false; if (!string.IsNullOrEmpty(pUser.Password)) { req.BusinessData.ChangePassword = new ChangePassword(); req.BusinessData.ChangePassword.New = pUser.Password; req.BusinessData.ChangePassword.Old = string.Empty; } UpdateUserRes res = req.ExecuteService<UpdateUserReq, UpdateUserRes>(WrapperSecurityProvider,req); if (res.Error != null) { throw Fwk.Exceptions.ExceptionHelper.ProcessException(res.Error); } }
public async Task <ActionResult <int> > Update(UpdateUserReq req) { return(Ok(await _userService.Update(UserId, req))); }
void UpdateUser_cpass_NO_Service(User oldUser) { UpdateUserReq req = new UpdateUserReq(); UpdateUserService svc = new UpdateUserService(); req.BusinessData.ChangePassword = new ChangePassword(); req.BusinessData.ChangePassword.New = "11111"; req.BusinessData.ChangePassword.Old = "66666"; req.BusinessData.UsersBE = oldUser; req.BusinessData.PasswordOnly = true; try { UpdateUserRes res = svc.Execute(req); } catch (Exception ex) { base.StrExceptionMessage = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex); } Assert.AreEqual<String>(base.StrExceptionMessage, String.Empty, base.StrExceptionMessage); }
void UpdateUser_NO_Service(User oldUser) { UpdateUserReq req = new UpdateUserReq(); UpdateUserService svc = new UpdateUserService(); req.BusinessData.UsersBE = oldUser; req.BusinessData.UsersBE.FirstName = oldUser.FirstName + "_updated"; req.BusinessData.UsersBE.LastName = oldUser.LastName + "_updated"; req.BusinessData.UsersBE.ModifiedByUserId = 12; req.BusinessData.UsersBE.ModifiedDate = System.DateTime.Now; req.BusinessData.UsersBE.Email = oldUser.Email + ".ar"; req.BusinessData.PasswordOnly = false; try { UpdateUserRes res = svc.Execute(req); } catch (Exception ex) { base.StrExceptionMessage = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex); } Assert.AreEqual<String>(base.StrExceptionMessage, String.Empty, base.StrExceptionMessage); }