/// <summary> /// Updates the user. /// </summary> /// <param name="user">The user.</param> /// <param name="operUser">The oper user.</param> /// <returns></returns> public bool Modify(Sys_AdminUser user, Sys_AdminUser operUser) { var b = false; if (user != null && user.id > 0) { var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; try { adminUserRepository.Modify(user); adminUserRepository.Uow.Commit(); b = true; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id.ToString() + " 改变用户Id号:" + user.id.ToString() + " 的信息"; log.FullMessage = "UpdateUser 用户名:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 改变了用户Id号:" + user.id.ToString() + " 的信息"; } else { log.UserId = 0; log.ShortMessage = "用户Id号:" + user.id.ToString() + " 的信息被修改"; log.FullMessage = "UpdateUser " + "用户Id号:" + user.id.ToString() + " 的信息被修改"; } } catch (Exception ex) { #region exception if (operUser != null && operUser.id > 0) { log.ShortMessage = "更新用户数据异常"; log.FullMessage = log.ShortMessage = "更新用户Id:" + user.id + " 用户名:" + user.username + " 操作用户Id:" + operUser.id + " 错误信息:" + ex.Message; if (ex.InnerException != null) { log.FullMessage += " 内部错误信息:" + ex.InnerException.Message; } } else { log.ShortMessage = "更新用户数据异常"; log.FullMessage = log.ShortMessage = "更新用户Id:" + user.id + " 用户名:" + user.username + " 错误信息:" + ex.Message; if (ex.InnerException != null) { log.FullMessage += " 内部错误信息:" + ex.InnerException.Message; } } #endregion } iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); } return b; }
public bool Add(IList<Sys_AdminUser> entity, Sys_AdminUser operUser) { var res = false; if (entity != null && entity.Count > 0) { try { foreach (var item in entity) { if (item != null && !ExistUserByName(item.username) && !ExistUserByEmail(item.Email)) { InitAddUser(item, operUser); adminUserRepository.Add(item); adminUserRepository.Uow.Commit(); var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id + " 添加一个新用户Id:" + item.id; log.FullMessage = "AddUser 用户名:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 添加用户Id:" + item.id + " 添加用户名:" + item.username; } else { log.UserId = 0; log.ShortMessage = "用户名:" + item.username + "被添加"; log.FullMessage = "AddUser " + "用户名:" + item.username + "被添加"; } iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); } } res = true; } catch (Exception ex) { } } return res; }
/// <summary> /// Deletes the user. /// </summary> /// <param name="user">The user.</param> /// <param name="operUser">The oper user.</param> /// <returns></returns> public bool Delete(Sys_AdminUser user, Sys_AdminUser operUser) { bool b = false; if (user != null && user.id > 0) { user.Activity = false; var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id.ToString() + " 非物理删除用户Id号:" + user.id.ToString(); log.FullMessage = "DeleteUser 用户名:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 非物理删除用户Id号:" + user.id.ToString(); } else { log.UserId = 0; log.ShortMessage = "用户Id:" + user.id.ToString() + " 被非物理删除"; log.FullMessage = "DeleteUser 用户名:" + user.username + " 用户Id:" + operUser.id.ToString() + " 被非物理删除"; } try { adminUserRepository.Uow.Commit(); b = true; iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); } catch (Exception ex) { } } return b; }
/// <summary> /// Users the change PWD by id. /// </summary> /// <param name="id">The id.</param> /// <param name="pwd">The PWD.</param> /// <returns></returns> public bool ModifyPwdById(int id, string pwd, Sys_AdminUser operUser) { bool b = false; pwd = iPow.Infrastructure.Crosscutting.Function.StringHelper.Tomd5(pwd); int res = ProcedureService.UserChangePwdById(id, pwd); if (res > 0) { b = true; var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id + " 改变用户Id号:" + id.ToString() + " 的密码"; log.FullMessage = "UserChangePwdById 用户:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 改变用户Id号:" + id.ToString() + " 的密码:" + pwd; } else { log.UserId = 0; log.ShortMessage = "用户Id号:" + id.ToString() + " 的密码被修改"; log.FullMessage = "UserChangePwdById " + "用户Id号:" + id.ToString() + " 的密码被修改"; } } return b; }
/// <summary> /// Deletes the user true. /// </summary> /// <param name="user">The user.</param> /// <param name="operUser">The oper user.</param> /// <returns></returns> public bool DeleteTrue(Sys_AdminUser user, Sys_AdminUser operUser) { bool b = false; if (user != null && user.id > 0) { try { //要删除角色 var userRoles = userRoleRepository.GetList(d => d.UserID == user.id); foreach (var item in userRoles) { userRoleRepository.Delete(item); } adminUserRepository.Delete(user); //用户扩展信息 var userExtension = adminUserExtensionRepository.GetList(d => d.UserId == user.id); foreach (var item in userExtension) { adminUserExtensionRepository.Delete(item); } //个性化设置内容 var userIndividu = adminUserIndividuationRepository.GetList(d => d.UserId == user.id); foreach (var item in userIndividu) { adminUserIndividuationRepository.Delete(item); } adminUserRepository.Uow.Commit(); userRoleRepository.Uow.Commit(); adminUserExtensionRepository.Uow.Commit(); adminUserIndividuationRepository.Uow.Commit(); //rolePermissionRepository.这是角色权限 var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id + " 物理删除用户Id号:" + user.id.ToString(); log.FullMessage = "DeleteUserTrue 用户:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 删除用户Id号:" + user.id.ToString(); } else { log.UserId = 0; log.ShortMessage = "用户Id号:" + user.id.ToString() + " 被删除"; log.FullMessage = "DeleteUserTrue " + "用户Id号:" + user.id.ToString() + " 被删除"; } iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); b = true; } catch (Exception ex) { } } return b; }
/// <summary> /// 创建新的 Sys_AdminUserLog 对象。 /// </summary> /// <param name="id">Id 属性的初始值。</param> public static Sys_AdminUserLog CreateSys_AdminUserLog(global::System.Int32 id) { Sys_AdminUserLog sys_AdminUserLog = new Sys_AdminUserLog(); sys_AdminUserLog.Id = id; return sys_AdminUserLog; }
/// <summary> /// 用于向 Sys_AdminUserLog EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToSys_AdminUserLog(Sys_AdminUserLog sys_AdminUserLog) { base.AddObject("Sys_AdminUserLog", sys_AdminUserLog); }
/// <summary> /// 用于在用户管理面板 添加一个没有Role的User /// </summary> /// <param name="user">The user.</param> /// <param name="userRole">The user role.</param> /// <param name="operUser">The oper user.</param> /// <returns></returns> public Sys_AdminUser Add(Sys_AdminUser user, iPow.Infrastructure.Data.DataSys.Sys_AdminUser operUser) { if (user != null) { if (!ExistUserByName(user.username) && !ExistUserByEmail(user.Email)) { try { #region admin user user.Activity = false; user.DepartmentID = "0"; //user.Email user.EmployeeID = 0; var userid = adminUserRepository.GetList().Max(e => e.id) + 1; //user.id = userid; user.lastloginip = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); user.lastlogintime = System.DateTime.Now; user.logintimes = 1; //user.password //user.Phone = ""; //user.sex = ""; user.style = 0; //user.truename = ""; user.UserGuid = iPow.Infrastructure.Crosscutting.Comm.Service.UserGuidService.BuilderUserGuid(); user.userid = operUser.id; //user.username adminUserRepository.Add(user); #endregion adminUserRepository.Uow.Commit(); var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id + " 添加一个新用户Id:" + user.id; log.FullMessage = "AddUser 用户名:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 添加用户Id:" + user.id + " 添加用户名:" + user.username; } else { log.UserId = 0; log.ShortMessage = "用户名:" + user.username + "被添加"; log.FullMessage = "AddUser " + "用户名:" + user.username + "被添加"; } iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); } catch (Exception ex) { user.id = 0; } } } return user; }
/// <summary> /// Exists the user by name PWD. /// </summary> /// <param name="name">The name.</param> /// <param name="pwd">The PWD.</param> /// <param name="login">if set to <c>true</c> [login].</param> /// <returns></returns> public bool ExistUserByNamePwd(string name, string pwd, bool login) { bool b = false; pwd = iPow.Infrastructure.Crosscutting.Function.StringHelper.Tomd5(pwd); var user = adminUserRepository.GetList(e => e.username == name) .Where(e => e.password == pwd) .Where(d => d.Activity == true) .FirstOrDefault(); if (user != null) { b = true; var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; log.UserId = 0; log.UserId = 0; log.FullMessage = "ExistUserByNamePwd 用户Id号:" + user.id.ToString(); log.ShortMessage = "查找用户名:" + name + " 密码:" + pwd + "成功"; //查找成功 if (login) { user.lastloginip = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); user.lastlogintime = System.DateTime.Now; user.logintimes += 1; //添加日志用户日志 log.ShortMessage = "用户名:" + name + " 密码:" + pwd + "登陆成功"; } iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); } return b; }
/// <summary> /// Regsters the user. /// </summary> /// <param name="entity">The user.</param> /// <param name="userRole">The user role.</param> /// <param name="operUser">The oper user.</param> /// <returns></returns> public bool Add(Sys_AdminUser entity, Sys_UserRoles userRole, iPow.Infrastructure.Data.DataSys.Sys_AdminUser operUser) { var res = false; if (entity != null && !ExistUserByName(entity.username) && !ExistUserByEmail(entity.Email)) { try { #region admin user InitAddUser(entity, operUser); adminUserRepository.Add(entity); adminUserRepository.Uow.Commit(); #endregion #region user role userRole.UserID = entity.id; userRoleRepository.Add(userRole); userRoleRepository.Uow.Commit(); #endregion var log = new Sys_AdminUserLog(); log.AddTime = System.DateTime.Now; log.IpAddress = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetRealIP(); log.PageUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetCurrentUrl(); log.ReferrerUrl = iPow.Infrastructure.Crosscutting.Function.StringHelper.GetReferrerUrl(); log.State = true; log.TypeId = 1; if (operUser != null) { log.UserId = operUser.id; log.ShortMessage = "用户Id:" + operUser.id + " 添加一个新用户Id:" + entity.id; log.FullMessage = "AddUser 用户名:" + operUser.username + " 用户Id:" + operUser.id.ToString() + " 添加用户Id:" + entity.id + " 添加用户名:" + entity.username + " 添加用户角色Id:" + userRole.RoleID; } else { log.UserId = 0; log.ShortMessage = "用户名:" + entity.username + "被添加"; log.FullMessage = "AddUser " + "用户名:" + entity.username + "被添加"; } iPow.Infrastructure.Data.LoggerReopsitoryManager.AddLogInfo(log); } catch (Exception ex) { entity.id = 0; } } return res; }