public async Task<IHttpActionResult> GetRolesByResGroupIDAsync(string resGroupID)
        {
            string groupName = resGroupID.Split(';')[0];
            string groupID = resGroupID.Split(';')[1];
            List<ResourcePageView> list = new List<ResourcePageView>();

            groupID = groupID.Replace("/", "&");

            //RetrieveRMResourcesByGroupID
            var operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.RMResourceGroups);
            var result = operation.RetrieveRMGroup(groupName);
            foreach (RMResourceGroupEntiry resGroupEntiry in result)
            {
                operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.RGRBACRoleAssignments);
                var RGBACRole_result = operation.RetrieveRGRBACRoleAssignmentByGroupID(groupID);
                foreach (RGRBACRoleAssignmentEntity entry in RGBACRole_result)
                {
                    var role_operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.RBACRoles);
                    var role_result = role_operation.RetrieveRbacRoleByID(entry.RowKey);
                    RBACRoleEntity rbacRole = new RBACRoleEntity();
                    foreach(RBACRoleEntity _temp in role_result)
                    {
                        rbacRole = _temp;
                        break;
                    }
                    operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.UserRBACRoleAssignments);
                    var userRBRole_result = operation.RetrieveUsersByRbacRoleId(entry.RowKey);
                    foreach (UserRBACRoleAssignmentEntity userRBACRoleAssignmentEntity in userRBRole_result)
                    {
                        ResourcePageView view = new ResourcePageView();
                        view.ResourceGroupName = resGroupEntiry.PartitionKey;
                        view.GroupID = resGroupEntiry.resourceGroupID;
                        view.UserID = "External AAD User";
                        view.UserPrincipleName = "External AAD User";
                        view.Location = resGroupEntiry.RowKey;
                        view.RoleName = rbacRole.RowKey;
                        view.RoleID = rbacRole.PartitionKey;
                        var user_operation= new TableDal(ConfigurationManager.AppSettings["storageConnection"],TableNames.AADUsers);
                        var user_result = user_operation.RetrieveUserByUserId(userRBACRoleAssignmentEntity.PartitionKey);
                        foreach(UserEntity userEntity in user_result)
                        {
                            view.UserID = userEntity.PartitionKey;
                            view.UserPrincipleName = userEntity.RowKey;
                            break;
                        }
                        list.Add(view);
                    }
                }
            }




            return CreateSuccessResult(list);
        }
Пример #2
0
        public async Task<IHttpActionResult> GetRMGroupsAsync(string userId)
        {
            #region get RBACRoleBy userID
            List<RBACRoleEntity> RBACRolelist = new List<RBACRoleEntity>();
            var operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.UserRBACRoleAssignments);
            var result = operation.RetrieveRolesByUserId(userId);
            foreach (UserRBACRoleAssignmentEntity entiry in result)
            {
                string roleId = entiry.RowKey;
                operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.RBACRoles);
                var RBAC_result = operation.RetrieveRbacRoleByID(roleId);
                foreach (RBACRoleEntity rb_entity in RBAC_result)
                {
                    RBACRolelist.Add(rb_entity);
                }
            }

            #endregion


            List<RmAccessGroupView> list = new List<RmAccessGroupView>();

            foreach (RBACRoleEntity rbacRole in RBACRolelist)
            {
                string roleId = rbacRole.PartitionKey;
                string roleName = rbacRole.RowKey;
                operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.RGRBACRoleAssignments);
                var RGresult = operation.RetrieveRMGroupsByRbacRoleId(roleId);
                foreach (RGRBACRoleAssignmentEntity RG_entity in RGresult)
                {
                    string rmGroupName = RG_entity.PartitionKey.Substring(RG_entity.PartitionKey.LastIndexOf("&") + 1);
                    operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.RMResourceGroups);
                    var RMresult = operation.RetrieveRMGroup(rmGroupName);
                    foreach (RMResourceGroupEntiry RmG_entity in RMresult)
                    {
                        list.Add(new RmAccessGroupView(RmG_entity, roleName));
                    }
                }

            }
            return CreateSuccessResult(list);
        }