Ejemplo n.º 1
0
        public IResult<ComponentInstance> GetFragment(IEnumerable<string> path, IEnumerable<KeyValuePair<string, string>> parameters, ClaimsPrincipal user, IEnumerable<int> componentPath)
        {
            var result = this.contentRepository.FindContent(path).TakeTemplateResult();

            if (result == null)
            {
                return new NotFoundResult<ComponentInstance>();
            }

            if (!result.Configuration.Conditions.SatisfiedBy(user))
            {
                return user?.Identity != null &&  user.Identity.IsAuthenticated
                           ? (IResult<ComponentInstance>)new ForbiddenResult<ComponentInstance>()
                           : (IResult<ComponentInstance>)new UnauthorisedResult<ComponentInstance>();
            }

            var context = this.BuildContext(parameters, result.Configuration);
            var page = this.BuildPage(result.Content as Template, true, context);

            var finder = new ComponentFindingComponentInstanceVisitor();

            var fragment = finder.Find(page, componentPath);

            return new SuccessResult<ComponentInstance>(fragment);
        }
Ejemplo n.º 2
0
        public IResult <ComponentInstance> GetFragment(IEnumerable <string> path, IEnumerable <KeyValuePair <string, string> > parameters, ClaimsPrincipal user, IEnumerable <int> componentPath)
        {
            var result = this.contentRepository.FindContent(path).TakeTemplateResult();

            if (result == null)
            {
                return(new NotFoundResult <ComponentInstance>());
            }

            if (!result.Configuration.Conditions.SatisfiedBy(user))
            {
                return(user?.Identity != null && user.Identity.IsAuthenticated
                           ? (IResult <ComponentInstance>) new ForbiddenResult <ComponentInstance>()
                           : (IResult <ComponentInstance>) new UnauthorisedResult <ComponentInstance>());
            }

            var context = this.BuildContext(parameters, result.Configuration);
            var page    = this.BuildPage(result.Content as Template, true, context);

            var finder = new ComponentFindingComponentInstanceVisitor();

            var fragment = finder.Find(page, componentPath);

            return(new SuccessResult <ComponentInstance>(fragment));
        }