Inheritance: Route, ILiteralRoute
Esempio n. 1
0
        protected virtual Func<PomonaContext, PomonaResponse> ResolveGetCollectionProperty(ResourcePropertyRoute route,
                                                                                           ResourceProperty property,
                                                                                           ResourceType resourceItemType)
        {
            if (this.capabilityResolver.PropertyIsMapped(property.PropertyInfo) || property.GetPropertyFormula() != null)
            {
                return
                    pr =>
                    {
                        // Check existance of parent here, cannot differentiate between an empty collection and not found.
                        var parent = pr.Node.Parent;
                        if (parent.Route.IsSingle)
                        {
                            if (!parent.Exists)
                                throw new ResourceNotFoundException("Resource not found.");
                        }

                        return new PomonaResponse(
                            parent
                                .Query()
                                .OfTypeIfRequired(pr.Node.Route.InputType)
                                .SelectManyEx(x => x.Apply(property.CreateGetterExpression))
                                .WrapActionResult(defaultPageSize : property.ExposedAsRepository ? (int?)null : int.MaxValue));
                    };
            }
            else
            {
                return
                    pr =>
                    {
                        var parentNode = pr.Node.Parent;
                        if (parentNode.Route.IsSingle)
                            return new PomonaResponse(((IEnumerable)property.GetValue(parentNode.Get())).AsQueryable());
                        return new PomonaResponse(
                            pr.Node.Parent
                              .Query()
                              .OfTypeIfRequired(pr.Node.Route.InputType)
                              .ToListDetectType()
                              .AsQueryable()
                              .SelectManyEx(x => x.Apply(property.CreateGetterExpression))
                              .WrapActionResult(defaultPageSize : property.ExposedAsRepository ? (int?)null : int.MaxValue));
                    };
            }
        }
Esempio n. 2
0
        protected virtual Func <PomonaContext, PomonaResponse> ResolveGetCollectionProperty(ResourcePropertyRoute route,
                                                                                            ResourceProperty property,
                                                                                            ResourceType resourceItemType)
        {
            if (this.capabilityResolver.PropertyIsMapped(property.PropertyInfo) || property.GetPropertyFormula() != null)
            {
                return
                    (pr =>
                {
                    // Check existance of parent here, cannot differentiate between an empty collection and not found.
                    var parent = pr.Node.Parent;
                    if (parent.Route.IsSingle)
                    {
                        if (!parent.Exists)
                        {
                            throw new ResourceNotFoundException("Resource not found.");
                        }
                    }

                    return new PomonaResponse(
                        parent
                        .Query()
                        .OfTypeIfRequired(pr.Node.Route.InputType)
                        .SelectManyEx(x => x.Apply(property.CreateGetterExpression))
                        .WrapActionResult(defaultPageSize: property.ExposedAsRepository ? (int?)null : int.MaxValue));
                });
            }
            else
            {
                return
                    (pr =>
                {
                    var parentNode = pr.Node.Parent;
                    if (parentNode.Route.IsSingle)
                    {
                        return new PomonaResponse(((IEnumerable)property.GetValue(parentNode.Get())).AsQueryable());
                    }
                    return new PomonaResponse(
                        pr.Node.Parent
                        .Query()
                        .OfTypeIfRequired(pr.Node.Route.InputType)
                        .ToListDetectType()
                        .AsQueryable()
                        .SelectManyEx(x => x.Apply(property.CreateGetterExpression))
                        .WrapActionResult(defaultPageSize: property.ExposedAsRepository ? (int?)null : int.MaxValue));
                });
            }
        }
Esempio n. 3
0
 protected virtual Func<PomonaContext, PomonaResponse> ResolveGetSingleProperty(ResourcePropertyRoute route,
                                                                                StructuredProperty property,
                                                                                ResourceType resourceType)
 {
     return
         pr =>
             new PomonaResponse(pr,
                                pr.Node.Parent.Query()
                                  .SelectEx(x => x.Apply(property.CreateGetterExpression))
                                  .WrapActionResult(QueryProjection.FirstOrDefault));
 }
Esempio n. 4
0
 protected virtual Func <PomonaContext, PomonaResponse> ResolveGetSingleProperty(ResourcePropertyRoute route,
                                                                                 StructuredProperty property,
                                                                                 ResourceType resourceType)
 {
     return
         (pr =>
          new PomonaResponse(pr,
                             pr.Node.Parent.Query()
                             .SelectEx(x => x.Apply(property.CreateGetterExpression))
                             .WrapActionResult(QueryProjection.FirstOrDefault)));
 }