/// <summary> /// 添加系统用户执行方法 /// </summary> /// <param name="request"> /// 数据源请求信息对象 /// </param> /// <param name="user"> /// 系统用户模型对象 /// </param> /// <returns> /// 执行方法结果 /// </returns> /// <exception cref="Exception"> /// 执行方法异常 /// </exception> public ActionResult AddUser([DataSourceRequest] DataSourceRequest request, UserModel user) { try { if (user != null) { this.systemUserService = new SystemUserService(); user.Status = 1; user.CreateTime = DateTime.Now; var sysUser = DataTransfer.Transfer<System_User>(user, typeof(UserModel)); sysUser.LoginPassword = Encrypt.HashBySHA1(sysUser.LoginName + sysUser.LoginPassword); sysUser.ID = this.systemUserService.AddUser(sysUser); if (sysUser.ID > 0) { return this.Json(new[] { sysUser }.ToDataSourceResult(request, this.ModelState)); } } } catch (Exception exception) { throw new Exception(exception.Message, exception); } return this.View(); }
public ActionResult ModifyUser([DataSourceRequest] DataSourceRequest request, UserModel user) { if (user != null && this.ModelState.IsValid) { this.systemUserService = new SystemUserService(); var systemUser = DataTransfer.Transfer<System_User>( user, typeof(UserModel)); this.systemUserService.ModifyUser(systemUser); //判断用户密码是否被修改过 var userModel = this.systemUserService.QueryByLoginName(systemUser.LoginName); if (userModel != null && userModel.LoginPassword != systemUser.LoginPassword) { var loginPassword = Encrypt.HashBySHA1(systemUser.LoginName + systemUser.LoginPassword); LogUtils.Log("用户“" + systemUser.LoginName + "”修改密码", "ModifyUser", Category.Info, Session.SessionID); this.systemUserService.UpdatePassWord(systemUser.ID, loginPassword); } } return this.Json(new[] { user }.ToDataSourceResult(request, this.ModelState)); }