Ejemplo n.º 1
0
        public static SearchResourceSetResponse ToResponse(this SearchResourceSetResult searchResourceSetResult)
        {
            if (searchResourceSetResult == null)
            {
                throw new ArgumentNullException(nameof(searchResourceSetResult));
            }

            return(new SearchResourceSetResponse
            {
                StartIndex = searchResourceSetResult.StartIndex,
                TotalResults = searchResourceSetResult.TotalResults,
                Content = searchResourceSetResult.Content == null ? new List <ResourceSetResponse>() : searchResourceSetResult.Content.Select(s => s.ToResponse())
            });
        }
        private static DatatableResponse Convert(DatatableRequest datatableRequest, Dictionary <string, Func <ResourceSet, string> > mapping, SearchResourceSetResult searchResult)
        {
            var response = new DatatableResponse();
            var data     = new List <List <object> >();

            if (searchResult.Content != null)
            {
                foreach (var resource in searchResult.Content)
                {
                    var row = new List <object>();
                    foreach (var column in datatableRequest.Columns.OrderBy(c => c.Data))
                    {
                        if (!mapping.ContainsKey(column.Name))
                        {
                            continue;
                        }

                        row.Add(mapping[column.Name](resource));
                    }

                    row.Add(resource.Scopes);
                    row.Add(resource.Id);
                    var policies = new List <ResourcePolicyResponse>();
                    if (resource.AuthPolicies != null)
                    {
                        foreach (var policy in resource.AuthPolicies)
                        {
                            policies.Add(new ResourcePolicyResponse
                            {
                                PolicyId    = policy.Id,
                                Permissions = policy.Claims.Select(c => $"{c.Type} : {c.Value}"),
                                Scopes      = policy.Scopes
                            });
                        }
                    }

                    row.Add(policies);
                    data.Add(row);
                }
            }

            return(new DatatableResponse
            {
                Draw = datatableRequest.Draw,
                Data = data,
                RecordsFiltered = searchResult.TotalResults,
                RecordsTotal = searchResult.TotalResults
            });
        }