예제 #1
0
        //Create By 唐万祯 at 2014/08/04
        /// <summary>
        /// 获取某个用户所有的操作
        /// </summary>
        /// <param name="accout">用户名</param>
        /// <returns></returns>
        public List <Operation> GetUserOperation(string accout)
        {
            var operations = new List <Operation>();

            var user = new DZAFCPortal.Authorization.DAL.UserService().GenericService.FirstOrDefault(p => p.Account == accout);

            if (user == null)
            {
                return(null);
            }

            var roleUsers = new DZAFCPortal.Authorization.DAL.RoleUserService().GenericService.GetAll(p => p.UserID == user.ID);

            foreach (var roleUser in roleUsers)
            {
                var temp = GetRoleOperation(roleUser.RoleID);
                if (temp != null && temp.Count > 0)
                {
                    operations.AddRange(temp);
                }
            }

            //去除重复项目
            var tempOp = new List <Operation>();

            foreach (var item in operations)
            {
                if (tempOp.Find(p => p.ID == item.ID) == null)
                {
                    tempOp.Add(item);
                }
            }

            return(tempOp);
        }
예제 #2
0
        /// <summary>
        /// 通过操作,获取拥有这些操作的用户列表
        /// </summary>
        /// <param name="ops">操作集合</param>
        /// <returns></returns>
        public List <User> GetUsersByOpration(IEnumerable <string> ops)
        {
            if (ops != null)
            {
                //通过操作获取角色
                var roleIds = new DZAFCPortal.Authorization.DAL.RoleOperationService().GenericService.GetAll(p => ops.Contains(p.OperationID)).Select(p => p.RoleID);

                if (roleIds != null)
                {
                    //通过角色获取用户
                    var userIds = new DZAFCPortal.Authorization.DAL.RoleUserService().GenericService.GetAll(p => roleIds.Contains(p.RoleID)).Select(p => p.UserID);
                    //获取用户实体

                    if (userIds != null)
                    {
                        var users = new DZAFCPortal.Authorization.DAL.UserService().GenericService.GetAll(p => userIds.Contains(p.ID)).ToList();
                        if (users != null)
                        {
                            return(users);
                        }
                    }
                }
            }

            return(new List <User>());
        }