Exemplo n.º 1
0
        /// <summary>
        /// Projects each product of a sequence into a new form.
        /// </summary>
        public static IQueryable <PageItem> Select(this IQueryable <PortalPage> query, PageField fields)
        {
            Expression <Func <PortalPage, PageItem> > selector = page => new PageItem
            {
                Id           = page.Id,
                Uri          = page.Uri,
                ModifiedDate = page.ModifiedDate,
                Name         = page.Name,
                Description  = page.Description
            };

            if (fields.HasFlag(PageField.Portal))
            {
                selector = selector.Merge(page => new PageItem
                {
                    Portal = new ResourceItem
                    {
                        Id   = page.Portal.Id,
                        Uri  = page.Portal.Uri,
                        Name = page.Portal.Name
                    }
                });
            }

            if (fields.HasFlag(PageField.Master))
            {
                selector = selector.Merge(page => new PageItem
                {
                    Master = page.Master == null ? null : new ResourceItem
                    {
                        Id   = page.Master.Id,
                        Uri  = PortalFunctions.GetPageUriById(page.Master.Id),
                        Name = page.Master.Name
                    }
                });
            }

            if (fields.HasFlag(PageField.Content))
            {
                selector = selector.Merge(page => new PageItem
                {
                    HtmlContent  = page.HtmlContent,
                    StyleContent = page.StyleContent
                });
            }

            return(query.Select(selector));
        }
 /// <summary>
 /// Applies this convention to an item in the model.
 /// </summary>
 /// <param name="item">The item to apply the convention to.</param>
 /// <param name="model">The model.</param>
 public void Apply(EdmModel item, DbModel model)
 {
     PortalFunctions.Register(item, model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Projects each product of a sequence into a new form.
        /// </summary>
        public static IQueryable <PortalItem> Select(this IQueryable <PortalEntity> query, IQueryable <SecurityAccessRule> acl, IQueryable <IdentityUser> users, PortalField fields)
        {
            Expression <Func <PortalEntity, PortalItem> > selector = portal => new PortalItem
            {
                Id           = portal.Id,
                Uri          = portal.Uri,
                Domain       = portal.Domain,
                CreatedDate  = portal.CreatedDate,
                ModifiedDate = portal.ModifiedDate,
                Name         = portal.Name,
                Description  = portal.Description,
                GATrackingId = portal.GATrackingId
            };

            if (fields.HasFlag(PortalField.Owners))
            {
                selector = selector.Merge(portal => new PortalItem
                {
                    Owners = (from ace in acl
                              where ace.ObjectType == AccessObjectType.Portal &&
                              ace.ObjectId == portal.Id &&
                              ace.UserId != null &&
                              ace.Permission == AccessPermission.IsOwner
                              orderby ace.Id
                              select ace.User)
                             .Select(MappingExpressions.ExprUserAsAccountItem)
                             .ToList()
                });
            }

            if (fields.HasFlag(PortalField.Project))
            {
                selector = selector.Merge(portal => new PortalItem
                {
                    Project = portal.Project == null ? null : new UniqueItem
                    {
                        Id   = portal.Project.Id,
                        Name = portal.Project.Name
                    }
                });
            }

            if (fields.HasFlag(PortalField.HomePage))
            {
                selector = selector.Merge(portal => new PortalItem
                {
                    HomePage = portal.HomePage == null ? null : new ResourceItem
                    {
                        Id   = portal.HomePage.Id,
                        Uri  = PortalFunctions.GetPageUriById(portal.HomePage.Id),
                        Name = portal.HomePage.Name
                    }
                });
            }

            if (fields.HasFlag(PortalField.MasterPage))
            {
                selector = selector.Merge(portal => new PortalItem
                {
                    MasterPage = portal.MasterPage == null ? null : new ResourceItem
                    {
                        Id   = portal.MasterPage.Id,
                        Uri  = PortalFunctions.GetPageUriById(portal.MasterPage.Id),
                        Name = portal.MasterPage.Name
                    }
                });
            }

            return(query.Select(selector));
        }