public object SaveUser_Role(string PageLoginNames, string RoleID) { string Message = string.Empty; int Success = 0; if (RoleID == "" || PageLoginNames == "") { return(new { Data = "", Success = 0, Message = "参数丢失" }); } try { List <string> oldLoginNames = S_Role_UserActionOperator.Instance.GetDataByRoleID(RoleID.ToGuid()); List <S_Role_User> entitys = new List <S_Role_User>(); string[] LoginNames = PageLoginNames.Split(','); if (LoginNames.Count() < 1) { return(new { Data = "", Success = 0, Message = "参数丢失" }); } foreach (var item in LoginNames) { if (oldLoginNames.Count > 0) { if (oldLoginNames.Contains(item)) { Message += "人员重复:" + item + ";不添加。"; continue; } } S_Role_User su = new S_Role_User(); su.RoleID = RoleID.ToGuid(); su.LoginName = item; su.CreateTime = DateTime.Now; su.CreatorName = base.CurrentUserName; su.IsDeleted = false; su.ModifierName = base.CurrentUserName; su.ModifyTime = DateTime.Now; su.ID = Guid.NewGuid(); entitys.Add(su); } foreach (var item in oldLoginNames) { if (!LoginNames.Contains(item)) { if (S_Role_UserActionOperator.Instance.DeleteDAtaByLoginNameAndRoleID(RoleID.ToGuid(), item) > 0) { Message += "已经取消人员:" + item + "的角色权限。"; } } } int resultData = S_Role_UserActionOperator.Instance.InsertListData(entitys); //清除缓存 WebHelper.InvalidAuthCache(); if (entitys.Count <= 0) { Success = 1; Message += "没有新增任何用户"; } else if (resultData > 0) { Success = 1; Message += "保存成功"; } else { Success = 0; Message += "新增用户信息保存失败"; } return(new { Data = "", Success = Success, Message = Message }); } catch (Exception ex) { return(new { Data = "", Success = 0, Message = ex.Message }); } }
public object SaveUsesRoles(string loginName, string roleIDs) { if (loginName == "") { return(new { Data = "", Success = 0, Message = "参数:用户账号信息没有传递;角色ID传递为null" }); } string message = string.Empty; int success = 0; try { var resutlDeleteUser_Role = S_Role_UserActionOperator.Instance.DeleteDatasByLoginName(loginName); if (roleIDs != null && roleIDs != "") { string[] roleIds = roleIDs.Split(','); if (roleIds.Length < 1) { return(new { Data = "", Success = 0, Message = "参数:角色ID传递为null" }); } List <S_Role_User> entitys = new List <S_Role_User>(); foreach (var item in roleIds) { S_Role_User su = new S_Role_User() { ID = Guid.NewGuid(), LoginName = loginName, RoleID = item.ToGuid(), IsDeleted = false, CreateTime = DateTime.Now, CreatorName = base.CurrentUserName, ModifierName = base.CurrentUserName, ModifyTime = DateTime.Now }; entitys.Add(su); } if (entitys.Count > 0) { int number = S_Role_UserActionOperator.Instance.InsertListData(entitys); if (number > 0) { success = 1; message = "设置角色成功"; } else { success = 0; message = "设置角色失败"; } } else { success = 1; message = "设置成功"; } } else { success = 1; message = "设置成功"; } //清除缓存 WebHelper.InvalidAuthCache(); return(new { Data = "", Success = success, Message = message }); } catch (Exception ex) { return(new { Data = "", Success = 0, Message = ex.Message }); } }