public void AssignForRole(int roleId, int moduleId, int[] menuIds) { var elements = _repository.Find(u => u.ModuleId == moduleId).Select(u => u.Id).ToArray(); _relevanceRepository.Delete(u => elements.Contains(u.SecondId) && u.Key == "RoleElement" && u.FirstId == roleId); _relevanceRepository.AddRelevance("RoleElement", menuIds.ToLookup(u => roleId)); }
public void AddOrUpdate(UserView view) { User user = view; if (user.Id == Guid.Empty) { if (_repository.IsExist(u => u.Account == view.Account)) { throw new Exception("用户账号已存在"); } user.CreateTime = DateTime.Now; user.Password = user.Account; //初始密码与账号相同 _repository.Add(user); view.Id = user.Id; //要把保存后的ID存入view } else { _repository.Update(u => u.Id == view.Id, u => new User { Account = user.Account, BizCode = user.BizCode, Name = user.Name, Sex = user.Sex, Status = user.Status, Type = user.Type, WeChat = user.WeChat }); } Guid[] orgIds = view.OrganizationIds.Split(',').Select(id => Guid.Parse(id)).ToArray(); _relevanceRepository.DeleteBy("UserOrg", user.Id); _relevanceRepository.AddRelevance("UserOrg", orgIds.ToLookup(u => user.Id)); }
public void AddOrUpdate(UserView view) { User user = view; if (user.Id == 0) { user.CreateTime = DateTime.Now; user.Password = user.Account; //初始密码与账号相同 _repository.Add(user); view.Id = user.Id; //要把保存后的ID存入view } else { _repository.Update(u => u.Id == view.Id, u => new User { Account = user.Account, BizCode = user.BizCode, CreateId = user.CreateId, Name = user.Name, Sex = user.Sex, Status = user.Status, Type = user.Type }); } int[] orgIds = view.OrganizationIds.Split(',').Select(id => int.Parse(id)).ToArray(); _relevanceRepository.DeleteBy("UserOrg", user.Id); _relevanceRepository.AddRelevance("UserOrg", orgIds.ToLookup(u => user.Id)); }
public void AddOrUpdate(JObject obj) { var role = obj.ToObject <Role>(); if (role.Id == Guid.Empty) { role.CreateTime = DateTime.Now; _repository.Add(role); } else { _repository.Update(role); } Guid[] orgIds = obj["OrganizationIds"].ToString().Split(',').Select(id => Guid.Parse(id)).ToArray(); _relevanceRepository.DeleteBy("RoleOrg", role.Id); _relevanceRepository.AddRelevance("RoleOrg", orgIds.ToLookup(u => role.Id)); }
/// <summary> /// 为特定的用户分配角色 /// </summary> /// <param name="userId">The user unique identifier.</param> /// <param name="ids">角色ID</param> public void AssignModuleForUser(int userId, int[] ids) { _relevanceRepository.DeleteBy("UserAccessedOrg", userId); _relevanceRepository.AddRelevance("UserAccessedOrg", ids.ToLookup(u => userId)); }
public void AccessRole(int userId, int[] roleIds) { _relevanceRepository.AddRelevance("UserRole", roleIds.ToLookup(roleId => userId)); }
/// <summary> /// 添加关联 /// <para>比如给用户分配资源,那么firstId就是用户ID,secIds就是资源ID列表</para> /// </summary> /// <param name="type">关联的类型,如"UserResource"</param> public void Assign(string type, Guid firstId, Guid[] secIds) { _relevanceRepository.AddRelevance(type, secIds.ToLookup(u => firstId)); }
public void AssignForRole(int roleId, int[] menuIds) { _relevanceRepository.AddRelevance("RoleElement", menuIds.ToLookup(u => roleId)); }
/// <summary> /// 为用户分配资源 /// </summary> /// <param name="userId">用户ID</param> /// <param name="resIds">资源ID数组</param> public void AssignResForUser(int userId, int[] resIds) { _relevanceRepository.DeleteBy("UserResource", resIds); _relevanceRepository.AddRelevance("UserResource", resIds.ToLookup(u => userId)); }