Rock.Model.LayoutService.GetBySiteId C# (CSharp) Method

GetBySiteId() public method

Gets the Layout by site id.
public GetBySiteId ( int siteId ) : IQueryable
siteId int The site id.
return IQueryable
        public IQueryable<Layout> GetBySiteId( int siteId )
        {
            return Queryable().Where( l => l.SiteId == siteId ).OrderBy( l => l.Name );
        }

Usage Example

Example #1
0
        /// <summary>
        /// Registers any layouts in a particular site's theme folder that do not currently have any layouts registered in Rock.
        /// </summary>
        /// <param name="physWebAppPath">A <see cref="System.String" /> containing the physical path to Rock on the server.</param>
        /// <param name="site">The site.</param>
        public static void RegisterLayouts(string physWebAppPath, SiteCache site)
        {
            // Dictionary for block types.  Key is path, value is friendly name
            var list = new Dictionary <string, string>();

            // Find all the layouts in theme layout folder...
            string layoutFolder = Path.Combine(physWebAppPath, string.Format("Themes\\{0}\\Layouts", site.Theme));

            // search for all layouts (aspx files) under the physical path
            var           layoutFiles = new List <string>();
            DirectoryInfo di          = new DirectoryInfo(layoutFolder);

            if (di.Exists)
            {
                foreach (var file in di.GetFiles("*.aspx", SearchOption.AllDirectories))
                {
                    layoutFiles.Add(Path.GetFileNameWithoutExtension(file.Name));
                }
            }

            var rockContext   = new RockContext();
            var layoutService = new LayoutService(rockContext);

            // Get a list of the layout filenames already registered
            var registered = layoutService.GetBySiteId(site.Id).Select(l => l.FileName).Distinct().ToList();

            // for each unregistered layout
            foreach (string layoutFile in layoutFiles.Except(registered, StringComparer.CurrentCultureIgnoreCase))
            {
                // Create new layout record and save it
                Layout layout = new Layout();
                layout.SiteId   = site.Id;
                layout.FileName = layoutFile;
                layout.Name     = layoutFile.SplitCase();
                layout.Guid     = new Guid();

                layoutService.Add(layout);
            }

            rockContext.SaveChanges();
        }
All Usage Examples Of Rock.Model.LayoutService::GetBySiteId