Esempio n. 1
0
        public static PaginatedSearchRequestDto DefaultInstance(ApplicationSchemaDefinition schema)
        {
            var defaultSize       = 30;
            var paginationOptions = DefaultPaginationOptions;

            if (schema != null)
            {
                var defaultSizeSt = schema.GetProperty(ApplicationSchemaPropertiesCatalog.DefaultPaginationSize);
                if (defaultSizeSt != null)
                {
                    defaultSize = Int32.Parse(defaultSizeSt);
                }
                var paginationOptionsSt = schema.GetProperty(ApplicationSchemaPropertiesCatalog.PaginationOptions);
                if (paginationOptionsSt != null)
                {
                    var paginationOptionsAux    = paginationOptionsSt.Split(',');
                    var paginationOptionListAux = new List <int>();
                    foreach (var s in paginationOptionsAux)
                    {
                        int option;
                        if (int.TryParse(s, out option))
                        {
                            paginationOptionListAux.Add(option);
                        }
                    }
                    if (paginationOptionListAux.Count > 0)
                    {
                        paginationOptions = paginationOptionListAux;
                    }
                }
            }
            return(new PaginatedSearchRequestDto(defaultSize, paginationOptions));
        }
Esempio n. 2
0
        public static AssociationHelperResult BuildAssociationsToPrefetch(IAssociationPrefetcherRequest request, ApplicationSchemaDefinition schema)
        {
            var schemaAssociations = schema.GetProperty(ApplicationSchemaPropertiesCatalog.PreFetchAssociations);
            var requestToFetch     = request.AssociationsToFetch;
            var result             = new AssociationHelperResult();
            var toFetch            = new HashedSet <string>();
            var toAvoid            = new HashedSet <string>();

            result.ToFetch = toFetch;
            result.ToAvoid = toAvoid;

            if (schemaAssociations == null && requestToFetch == null)
            {
                toFetch.AddReturn(None);
                return(result);
            }
            if (All.Equals(schemaAssociations))
            {
                toFetch.Add(None.Equals(requestToFetch) ? None : All);
                return(result);
            }
            if (All.Equals(requestToFetch))
            {
                toFetch.AddReturn(All);
                return(result);
            }

            if (schemaAssociations != null)
            {
                toFetch.AddAll(schemaAssociations.Split(','));
                if (AllButSchema.Equals(requestToFetch))
                {
                    toAvoid.AddAll(schemaAssociations.Split(','));
                }
            }

            if (requestToFetch != null)
            {
                toFetch.AddAll(requestToFetch.Split(','));
            }

            return(result);
        }