Exemplo n.º 1
0
        internal string BuildLinkEntity <T>(List <LinkEntityData> linkedEntities)
        {
            var sb = new StringBuilder();

            foreach (var link in linkedEntities)
            {
                string filter = null;

                var test = link.EntityType;
                try
                {
                    filter = BaseModel.BuildFilter(link.EntityType, new StringValues(link.Filters));
                }
                catch (InvalidFilterFieldException e)
                {
                    exceptions.Add(e);
                }

                var fetchPiece = $@"<link-entity name='{link.EntityName}' {link.JoinMapping} alias='{link.Alias}'>
                    {filter}
                </link-entity>";

                sb.Append(fetchPiece);
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        internal string BuildFetch <T>(string entityName, string[] additionalFilters, List <LinkEntityData> linkedEntities)
            where T : BaseModel
        {
            string filter     = null;
            string filter2    = null;
            string links      = null;
            string attributes = null;
            string paging     = null;

            attributes = BaseModel.SelectAttributes <T>(Request.Query["fields"]);

            try
            {
                filter  = BaseModel.BuildFilter(typeof(T), Request.Query["filter"]);
                filter2 = BaseModel.BuildFilter(typeof(T), new StringValues(additionalFilters));
            }
            catch (InvalidFilterFieldException e)
            {
                exceptions.Add(e);
            }

            if (linkedEntities != null && linkedEntities.Count > 0)
            {
                links = BuildLinkEntity <T>(linkedEntities);
            }

            try
            {
                paging = BaseModel.BuildPaging <T>(Request.Query["limit"], Request.Query["offset"]);
            }
            catch (InvalidFilterFieldException e)
            {
                exceptions.Add(e);
            }

            var fetch = $@"<fetch{paging}>
                <entity name='{entityName}'>
                    {attributes}
                    {filter}
                    {filter2}
                    {links}
                </entity>
            </fetch>";

            return(Uri.EscapeDataString(fetch));
        }