Exemplo n.º 1
0
        public IHateoasResource <TResource> CreateResource <TResource, TEntity>(TEntity entity, Func <TEntity, TResource> transformation, Action <IHateoasResourceBuilder <TResource, TEntity> > buildAction)
        {
            IHateoasResourceBuilder <TResource, TEntity> builder = ResourceBuilderFactory.Create <TResource, TEntity>();

            buildAction.Invoke(builder);

            return(builder.Build(entity, transformation));
        }
Exemplo n.º 2
0
        public IHateoasResource <TResource> CreateResource <TResource>(TResource resource, Action <IHateoasResourceBuilder <TResource> > buildAction)
        {
            IHateoasResourceBuilder <TResource> builder = ResourceBuilderFactory.Create <TResource>();

            buildAction.Invoke(builder);

            return(builder.Build(resource));
        }
        private IEnumerable <IHateoasResource <TResource> > GetResources(IEnumerable <TEntity> entities, Func <TEntity, TResource> transformation)
        {
            foreach (TEntity entity in entities)
            {
                TResource resource = transformation.Invoke(entity);

                IHateoasResourceBuilder <TResource> builder = ResourceBuilderFactory.Create <TResource>();
                builder.Links.AddLinks(Resources.Build(resource, entity));

                yield return(builder.Build(resource));
            }
        }