Esempio n. 1
0
 public void Post([FromBody] Module Module)
 {
     if (ModelState.IsValid)
     {
         modules.AddModule(Module);
     }
 }
        public Page Post(int id, string userid)
        {
            Page page   = null;
            Page parent = _pages.GetPage(id);

            if (parent != null && parent.IsPersonalizable && _userPermissions.GetUser(User).UserId == int.Parse(userid))
            {
                page              = new Page();
                page.SiteId       = parent.SiteId;
                page.Name         = parent.Name;
                page.Path         = parent.Path;
                page.ParentId     = parent.PageId;
                page.Order        = 0;
                page.IsNavigation = false;
                page.EditMode     = false;
                page.ThemeType    = parent.ThemeType;
                page.LayoutType   = parent.LayoutType;
                page.Icon         = parent.Icon;
                page.Permissions  = _permissionRepository.EncodePermissions(new List <Permission> {
                    new Permission(PermissionNames.View, userid, true),
                    new Permission(PermissionNames.Edit, userid, true)
                });
                page.IsPersonalizable = false;
                page.UserId           = int.Parse(userid);
                page = _pages.AddPage(page);
                _syncManager.AddSyncEvent(EntityNames.Site, page.SiteId);

                // copy modules
                List <PageModule> pagemodules = _pageModules.GetPageModules(page.SiteId).ToList();
                foreach (PageModule pm in pagemodules.Where(item => item.PageId == parent.PageId && !item.IsDeleted))
                {
                    Module module = new Module();
                    module.SiteId = page.SiteId;
                    module.PageId = page.PageId;
                    module.ModuleDefinitionName = pm.Module.ModuleDefinitionName;
                    module.Permissions          = _permissionRepository.EncodePermissions(new List <Permission> {
                        new Permission(PermissionNames.View, userid, true),
                        new Permission(PermissionNames.Edit, userid, true)
                    });
                    module = _modules.AddModule(module);

                    string content = _modules.ExportModule(pm.ModuleId);
                    if (content != "")
                    {
                        _modules.ImportModule(module.ModuleId, content);
                    }

                    PageModule pagemodule = new PageModule();
                    pagemodule.PageId        = page.PageId;
                    pagemodule.ModuleId      = module.ModuleId;
                    pagemodule.Title         = pm.Title;
                    pagemodule.Pane          = pm.Pane;
                    pagemodule.Order         = pm.Order;
                    pagemodule.ContainerType = pm.ContainerType;

                    _pageModules.AddPageModule(pagemodule);
                }
            }
            return(page);
        }
Esempio n. 3
0
 public Module Post([FromBody] Module Module)
 {
     if (ModelState.IsValid)
     {
         Module = Modules.AddModule(Module);
     }
     return(Module);
 }
Esempio n. 4
0
        public Page Post(int id, string userid)
        {
            Page page = null;
            Page parent = Pages.GetPage(id);
            if (parent != null && parent.IsPersonalizable && UserPermissions.GetUser(User).UserId == int.Parse(userid))
            {
                page = new Page();
                page.SiteId = parent.SiteId;
                page.Name = parent.Name;
                page.Path = parent.Path;
                page.ParentId = parent.PageId;
                page.Order = 0;
                page.IsNavigation = false;
                page.EditMode = false;
                page.ThemeType = parent.ThemeType;
                page.LayoutType = parent.LayoutType;
                page.Icon = parent.Icon;
                List<PermissionString> permissions = new List<PermissionString>();
                permissions.Add(new PermissionString { PermissionName = "View", Permissions = "[" + userid + "]" });
                permissions.Add(new PermissionString { PermissionName = "Edit", Permissions = "[" + userid + "]" });
                page.Permissions = UserSecurity.SetPermissionStrings(permissions);
                page.IsPersonalizable = false;
                page.UserId = int.Parse(userid);
                page = Pages.AddPage(page);

                // copy modules
                List<PageModule> pagemodules = PageModules.GetPageModules(page.SiteId).ToList();
                foreach (PageModule pm in pagemodules.Where(item => item.PageId == parent.PageId && !item.IsDeleted))
                {
                    Module module = new Module();
                    module.SiteId = page.SiteId;
                    module.PageId = page.PageId;
                    module.ModuleDefinitionName = pm.Module.ModuleDefinitionName;
                    permissions = new List<PermissionString>();
                    permissions.Add(new PermissionString { PermissionName = "View", Permissions = "[" + userid + "]" });
                    permissions.Add(new PermissionString { PermissionName = "Edit", Permissions = "[" + userid + "]" });
                    module.Permissions = UserSecurity.SetPermissionStrings(permissions);
                    module = Modules.AddModule(module);

                    string content = Modules.ExportModule(pm.ModuleId);
                    if (content != "")
                    {
                        Modules.ImportModule(module.ModuleId, content);
                    }

                    PageModule pagemodule = new PageModule();
                    pagemodule.PageId = page.PageId;
                    pagemodule.ModuleId = module.ModuleId;
                    pagemodule.Title = pm.Title;
                    pagemodule.Pane = pm.Pane;
                    pagemodule.Order = pm.Order;
                    pagemodule.ContainerType = pm.ContainerType;

                    PageModules.AddPageModule(pagemodule);
                }
            }
            return page;
        }
Esempio n. 5
0
 public Module Post([FromBody] Module Module)
 {
     if (ModelState.IsValid && UserPermissions.IsAuthorized(User, "Edit", Module.Permissions))
     {
         Module = Modules.AddModule(Module);
         logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", Module);
     }
     return(Module);
 }
 public Models.Module Post([FromBody] Models.Module Module)
 {
     if (ModelState.IsValid)
     {
         Module = Modules.AddModule(Module);
         logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", Module);
     }
     return(Module);
 }
 public Module Post([FromBody] Module module)
 {
     if (ModelState.IsValid && _userPermissions.IsAuthorized(User, EntityNames.Page, module.PageId, PermissionNames.Edit))
     {
         module = _modules.AddModule(module);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", module);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Module {Module}", module);
         HttpContext.Response.StatusCode = 401;
         module = null;
     }
     return(module);
 }
 public Models.Module Post([FromBody] Models.Module Module)
 {
     if (ModelState.IsValid && UserPermissions.IsAuthorized(User, "Page", Module.PageId, "Edit"))
     {
         Module = Modules.AddModule(Module);
         logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", Module);
     }
     else
     {
         logger.Log(LogLevel.Error, this, LogFunction.Create, "User Not Authorized To Add Module {Module}", Module);
         HttpContext.Response.StatusCode = 401;
         Module = null;
     }
     return(Module);
 }
Esempio n. 9
0
 public Module Post([FromBody] Module module)
 {
     if (ModelState.IsValid && module.SiteId == _alias.SiteId && _userPermissions.IsAuthorized(User, EntityNames.Page, module.PageId, PermissionNames.Edit))
     {
         module = _modules.AddModule(module);
         _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, _alias.SiteId);
         _logger.Log(LogLevel.Information, this, LogFunction.Create, "Module Added {Module}", module);
     }
     else
     {
         _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Module Post Attempt {Module}", module);
         HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
         module = null;
     }
     return(module);
 }
Esempio n. 10
0
        public async Task <ActionResult <ModuleDto> > CreateModule(ModuleDto module)
        {
            try
            {
                if (module == null)
                {
                    return(BadRequest());
                }
                var createdModule = await _moduleRepository.AddModule(module);

                return(CreatedAtAction(nameof(_moduleRepository.GetModule), new { id = createdModule.ModuleId }, createdModule));
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error retrieving data from the database"));
            }
        }
        public static IMvcBuilder LoadModules(this IMvcBuilder mvcBuilder, IModuleRepository moduleRepository)
        {
            var moduleAssemblies = new List <Assembly>();

            foreach (var library in DependencyContext.Default.RuntimeLibraries)
            {
                if (library.Name.StartsWith(modulePrefix))
                {
                    var moduleAssembly = Assembly.Load(new AssemblyName(library.Name));
                    moduleAssemblies.Add(moduleAssembly);

                    // The prefix is 15 chars.
                    var niceName = library.Name.Remove(0, 15);

                    // Insert the modules in the module repository.
                    var module = new Modular.Core.Module(niceName);
                    moduleRepository.AddModule(module);
                }
            }

            var fileProviders = new List <IFileProvider>();

            foreach (var moduleAssembly in moduleAssemblies)
            {
                // Add the module as an application part, so view components will be usable.
                mvcBuilder.AddApplicationPart(moduleAssembly);

                // Create an embedded file provider for static content like views.
                var fileProvider = new EmbeddedFileProvider(moduleAssembly);
                fileProviders.Add(fileProvider);
            }

            mvcBuilder.AddRazorOptions(options =>
            {
                // Add each file provider to the razor engine.
                foreach (var fileProvider in fileProviders)
                {
                    options.FileProviders.Add(fileProvider);
                }
            });

            return(mvcBuilder);
        }
Esempio n. 12
0
        public void AddFlowToModule(string route, string system, string moduleName, FlowDefinition flow)
        {
            var moduleExists = _moduleRepository.Exists(route, system, moduleName);

            if (moduleExists)
            {
                _moduleRepository.AddFlowToExistingModule(route, system, moduleName, flow);
            }
            else
            {
                var module = new ModuleDefinition
                {
                    Route  = route,
                    System = system,
                    Module = moduleName,
                    Flows  = new List <FlowDefinition>
                    {
                        flow
                    }
                };
                _moduleRepository.AddModule(module);
            }
        }
Esempio n. 13
0
        private void CreatePages(Site site, List <PageTemplate> pageTemplates)
        {
            List <ModuleDefinition> moduledefinitions = _moduleDefinitionRepository.GetModuleDefinitions(site.SiteId).ToList();

            foreach (PageTemplate pagetemplate in pageTemplates)
            {
                int?parentid = null;
                if (pagetemplate.Parent != "")
                {
                    List <Page> pages  = _pageRepository.GetPages(site.SiteId).ToList();
                    Page        parent = pages.Where(item => item.Name == pagetemplate.Parent).FirstOrDefault();
                    parentid = parent.PageId;
                }

                Page page = new Page
                {
                    SiteId           = site.SiteId,
                    ParentId         = parentid,
                    Name             = pagetemplate.Name,
                    Path             = pagetemplate.Path,
                    Order            = 1,
                    IsNavigation     = pagetemplate.IsNavigation,
                    EditMode         = pagetemplate.EditMode,
                    ThemeType        = "",
                    LayoutType       = "",
                    Icon             = pagetemplate.Icon,
                    Permissions      = pagetemplate.PagePermissions,
                    IsPersonalizable = pagetemplate.IsPersonalizable,
                    UserId           = null
                };
                page = _pageRepository.AddPage(page);

                foreach (PageTemplateModule pagetemplatemodule in pagetemplate.PageTemplateModules)
                {
                    if (pagetemplatemodule.ModuleDefinitionName != "")
                    {
                        ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == pagetemplatemodule.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            Module module = new Module
                            {
                                SiteId = site.SiteId,
                                ModuleDefinitionName = pagetemplatemodule.ModuleDefinitionName,
                                Permissions          = pagetemplatemodule.ModulePermissions,
                            };
                            module = _moduleRepository.AddModule(module);

                            if (pagetemplatemodule.Content != "" && moduledefinition.ServerAssemblyName != "")
                            {
                                Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
                                                    .Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
                                if (assembly != null)
                                {
                                    Type moduletype = assembly.GetTypes()
                                                      .Where(item => item.Namespace != null)
                                                      .Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
                                                      .Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
                                    if (moduletype != null)
                                    {
                                        var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
                                        ((IPortable)moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version);
                                    }
                                }
                            }

                            PageModule pagemodule = new PageModule
                            {
                                PageId        = page.PageId,
                                ModuleId      = module.ModuleId,
                                Title         = pagetemplatemodule.Title,
                                Pane          = pagetemplatemodule.Pane,
                                Order         = 1,
                                ContainerType = ""
                            };
                            _pageModuleRepository.AddPageModule(pagemodule);
                        }
                    }
                }
            }
        }
Esempio n. 14
0
        private void CreateSite(Site site)
        {
            RoleRepository.AddRole(new Role {
                SiteId = null, Name = Constants.AllUsersRole, Description = "All Users", IsAutoAssigned = false, IsSystem = true
            });
            RoleRepository.AddRole(new Role {
                SiteId = null, Name = Constants.HostRole, Description = "Application Administrators", IsAutoAssigned = false, IsSystem = true
            });

            RoleRepository.AddRole(new Role {
                SiteId = site.SiteId, Name = Constants.RegisteredRole, Description = "Registered Users", IsAutoAssigned = true, IsSystem = true
            });
            RoleRepository.AddRole(new Role {
                SiteId = site.SiteId, Name = Constants.AdminRole, Description = "Site Administrators", IsAutoAssigned = false, IsSystem = true
            });

            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "FirstName", Title = "First Name", Description = "Your First Or Given Name", Category = "Name", ViewOrder = 1, MaxLength = 50, DefaultValue = "", IsRequired = true, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "LastName", Title = "Last Name", Description = "Your Last Or Family Name", Category = "Name", ViewOrder = 2, MaxLength = 50, DefaultValue = "", IsRequired = true, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Street", Title = "Street", Description = "Street Or Building Address", Category = "Address", ViewOrder = 3, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "City", Title = "City", Description = "City", Category = "Address", ViewOrder = 4, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Region", Title = "Region", Description = "State Or Province", Category = "Address", ViewOrder = 5, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Country", Title = "Country", Description = "Country", Category = "Address", ViewOrder = 6, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "PostalCode", Title = "Postal Code", Description = "Postal Code Or Zip Code", Category = "Address", ViewOrder = 7, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Phone", Title = "Phone Number", Description = "Phone Number", Category = "Contact", ViewOrder = 8, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });

            foreach (PageTemplate pagetemplate in SiteTemplate)
            {
                int?parentid = null;
                if (pagetemplate.Parent != "")
                {
                    List <Page> pages  = PageRepository.GetPages(site.SiteId).ToList();
                    Page        parent = pages.Where(item => item.Name == pagetemplate.Parent).FirstOrDefault();
                    parentid = parent.PageId;
                }

                Page page = new Page
                {
                    SiteId       = site.SiteId,
                    ParentId     = parentid,
                    Name         = pagetemplate.Name,
                    Path         = pagetemplate.Path,
                    Order        = pagetemplate.Order,
                    IsNavigation = pagetemplate.IsNavigation,
                    ThemeType    = site.DefaultThemeType,
                    LayoutType   = site.DefaultLayoutType,
                    Icon         = pagetemplate.Icon,
                    Permissions  = pagetemplate.PagePermissions
                };
                Type type = Type.GetType(page.ThemeType);
                System.Reflection.PropertyInfo property = type.GetProperty("Panes");
                page.Panes = (string)property.GetValue(Activator.CreateInstance(type), null);
                page       = PageRepository.AddPage(page);

                if (pagetemplate.ModuleDefinitionName != "")
                {
                    Module module = new Module
                    {
                        SiteId = site.SiteId,
                        ModuleDefinitionName = pagetemplate.ModuleDefinitionName,
                        Permissions          = pagetemplate.ModulePermissions,
                    };
                    module = ModuleRepository.AddModule(module);

                    PageModule pagemodule = new PageModule
                    {
                        PageId        = page.PageId,
                        ModuleId      = module.ModuleId,
                        Title         = pagetemplate.Title,
                        Pane          = pagetemplate.Pane,
                        Order         = 1,
                        ContainerType = pagetemplate.ContainerType
                    };
                    PageModuleRepository.AddPageModule(pagemodule);
                }
            }
        }
Esempio n. 15
0
        public void CreatePages(Site site, List <PageTemplate> pageTemplates)
        {
            List <ModuleDefinition> moduledefinitions = _moduleDefinitionRepository.GetModuleDefinitions(site.SiteId).ToList();

            foreach (PageTemplate pagetemplate in pageTemplates)
            {
                int?parentid = null;
                if (pagetemplate.Parent != "")
                {
                    List <Page> pages  = _pageRepository.GetPages(site.SiteId).ToList();
                    Page        parent = pages.Where(item => item.Name == pagetemplate.Parent).FirstOrDefault();
                    parentid = parent.PageId;
                }

                Page page = new Page
                {
                    SiteId               = site.SiteId,
                    ParentId             = parentid,
                    Name                 = pagetemplate.Name,
                    Title                = "",
                    Path                 = pagetemplate.Path,
                    Order                = 1,
                    Url                  = "",
                    IsNavigation         = pagetemplate.IsNavigation,
                    ThemeType            = "",
                    LayoutType           = "",
                    DefaultContainerType = "",
                    Icon                 = pagetemplate.Icon,
                    Permissions          = pagetemplate.PagePermissions,
                    IsPersonalizable     = pagetemplate.IsPersonalizable,
                    UserId               = null
                };
                page = _pageRepository.AddPage(page);

                foreach (PageTemplateModule pagetemplatemodule in pagetemplate.PageTemplateModules)
                {
                    if (pagetemplatemodule.ModuleDefinitionName != "")
                    {
                        ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == pagetemplatemodule.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            Module module = new Module
                            {
                                SiteId = site.SiteId,
                                ModuleDefinitionName = pagetemplatemodule.ModuleDefinitionName,
                                AllPages             = false,
                                Permissions          = pagetemplatemodule.ModulePermissions,
                            };
                            module = _moduleRepository.AddModule(module);

                            if (pagetemplatemodule.Content != "" && moduledefinition.ServerManagerType != "")
                            {
                                Type moduletype = Type.GetType(moduledefinition.ServerManagerType);
                                if (moduletype != null && moduletype.GetInterface("IPortable") != null)
                                {
                                    try
                                    {
                                        var moduleobject = ActivatorUtilities.CreateInstance(_serviceProvider, moduletype);
                                        ((IPortable)moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version);
                                    }
                                    catch
                                    {
                                        // error in IPortable implementation
                                    }
                                }
                            }

                            PageModule pagemodule = new PageModule
                            {
                                PageId        = page.PageId,
                                ModuleId      = module.ModuleId,
                                Title         = pagetemplatemodule.Title,
                                Pane          = pagetemplatemodule.Pane,
                                Order         = 1,
                                ContainerType = ""
                            };
                            _pageModuleRepository.AddPageModule(pagemodule);
                        }
                    }
                }
            }
        }
        private void CreateSite(Site site)
        {
            List <Role> roles = RoleRepository.GetRoles(site.SiteId, true).ToList();

            if (!roles.Where(item => item.Name == Constants.AllUsersRole).Any())
            {
                RoleRepository.AddRole(new Role {
                    SiteId = null, Name = Constants.AllUsersRole, Description = "All Users", IsAutoAssigned = false, IsSystem = true
                });
            }
            if (!roles.Where(item => item.Name == Constants.HostRole).Any())
            {
                RoleRepository.AddRole(new Role {
                    SiteId = null, Name = Constants.HostRole, Description = "Application Administrators", IsAutoAssigned = false, IsSystem = true
                });
            }

            RoleRepository.AddRole(new Role {
                SiteId = site.SiteId, Name = Constants.RegisteredRole, Description = "Registered Users", IsAutoAssigned = true, IsSystem = true
            });
            RoleRepository.AddRole(new Role {
                SiteId = site.SiteId, Name = Constants.AdminRole, Description = "Site Administrators", IsAutoAssigned = false, IsSystem = true
            });

            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "FirstName", Title = "First Name", Description = "Your First Or Given Name", Category = "Name", ViewOrder = 1, MaxLength = 50, DefaultValue = "", IsRequired = true, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "LastName", Title = "Last Name", Description = "Your Last Or Family Name", Category = "Name", ViewOrder = 2, MaxLength = 50, DefaultValue = "", IsRequired = true, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Street", Title = "Street", Description = "Street Or Building Address", Category = "Address", ViewOrder = 3, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "City", Title = "City", Description = "City", Category = "Address", ViewOrder = 4, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Region", Title = "Region", Description = "State Or Province", Category = "Address", ViewOrder = 5, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Country", Title = "Country", Description = "Country", Category = "Address", ViewOrder = 6, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "PostalCode", Title = "Postal Code", Description = "Postal Code Or Zip Code", Category = "Address", ViewOrder = 7, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });
            ProfileRepository.AddProfile(new Profile {
                SiteId = site.SiteId, Name = "Phone", Title = "Phone Number", Description = "Phone Number", Category = "Contact", ViewOrder = 8, MaxLength = 50, DefaultValue = "", IsRequired = false, IsPrivate = false
            });

            Folder folder = FolderRepository.AddFolder(new Folder {
                SiteId = site.SiteId, ParentId = null, Name = "Root", Path = "", Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]"
            });

            FolderRepository.AddFolder(new Folder {
                SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = "Users\\", Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]"
            });
            if (site.Name == "Default Site")
            {
                File file = FileRepository.AddFile(new File {
                    FolderId = folder.FolderId, Name = "logo.png", Extension = "png", Size = 8192
                });
                site.LogoFileId = file.FileId;
                UpdateSite(site);
            }

            List <ModuleDefinition> moduledefinitions = ModuleDefinitionRepository.GetModuleDefinitions(site.SiteId).ToList();

            foreach (PageTemplate pagetemplate in SiteTemplate)
            {
                int?parentid = null;
                if (pagetemplate.Parent != "")
                {
                    List <Page> pages  = PageRepository.GetPages(site.SiteId).ToList();
                    Page        parent = pages.Where(item => item.Name == pagetemplate.Parent).FirstOrDefault();
                    parentid = parent.PageId;
                }

                Page page = new Page
                {
                    SiteId           = site.SiteId,
                    ParentId         = parentid,
                    Name             = pagetemplate.Name,
                    Path             = pagetemplate.Path,
                    Order            = 1,
                    IsNavigation     = pagetemplate.IsNavigation,
                    EditMode         = pagetemplate.EditMode,
                    ThemeType        = "",
                    LayoutType       = "",
                    Icon             = pagetemplate.Icon,
                    Permissions      = pagetemplate.PagePermissions,
                    IsPersonalizable = pagetemplate.IsPersonalizable,
                    UserId           = null
                };
                page = PageRepository.AddPage(page);

                foreach (PageTemplateModule pagetemplatemodule in pagetemplate.PageTemplateModules)
                {
                    if (pagetemplatemodule.ModuleDefinitionName != "")
                    {
                        ModuleDefinition moduledefinition = moduledefinitions.Where(item => item.ModuleDefinitionName == pagetemplatemodule.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            Models.Module module = new Models.Module
                            {
                                SiteId = site.SiteId,
                                ModuleDefinitionName = pagetemplatemodule.ModuleDefinitionName,
                                Permissions          = pagetemplatemodule.ModulePermissions,
                            };
                            module = ModuleRepository.AddModule(module);

                            if (pagetemplatemodule.Content != "" && moduledefinition.ServerAssemblyName != "")
                            {
                                Assembly assembly = AppDomain.CurrentDomain.GetAssemblies()
                                                    .Where(item => item.FullName.StartsWith(moduledefinition.ServerAssemblyName)).FirstOrDefault();
                                if (assembly != null)
                                {
                                    Type moduletype = assembly.GetTypes()
                                                      .Where(item => item.Namespace != null)
                                                      .Where(item => item.Namespace.StartsWith(moduledefinition.ModuleDefinitionName.Substring(0, moduledefinition.ModuleDefinitionName.IndexOf(","))))
                                                      .Where(item => item.GetInterfaces().Contains(typeof(IPortable))).FirstOrDefault();
                                    if (moduletype != null)
                                    {
                                        var moduleobject = ActivatorUtilities.CreateInstance(ServiceProvider, moduletype);
                                        ((IPortable)moduleobject).ImportModule(module, pagetemplatemodule.Content, moduledefinition.Version);
                                    }
                                }
                            }

                            PageModule pagemodule = new PageModule
                            {
                                PageId        = page.PageId,
                                ModuleId      = module.ModuleId,
                                Title         = pagetemplatemodule.Title,
                                Pane          = pagetemplatemodule.Pane,
                                Order         = 1,
                                ContainerType = ""
                            };
                            PageModuleRepository.AddPageModule(pagemodule);
                        }
                    }
                }
            }
        }
Esempio n. 17
0
        public Page Post(int id, string userid)
        {
            Page page   = null;
            Page parent = _pages.GetPage(id);

            if (parent != null && parent.SiteId == _alias.SiteId && parent.IsPersonalizable && _userPermissions.GetUser(User).UserId == int.Parse(userid))
            {
                page                      = new Page();
                page.SiteId               = parent.SiteId;
                page.Name                 = parent.Name;
                page.Title                = parent.Title;
                page.Path                 = parent.Path;
                page.ParentId             = parent.PageId;
                page.Order                = 0;
                page.IsNavigation         = false;
                page.Url                  = "";
                page.ThemeType            = parent.ThemeType;
                page.DefaultContainerType = parent.DefaultContainerType;
                page.Icon                 = parent.Icon;
                page.Permissions          = new List <Permission> {
                    new Permission(PermissionNames.View, int.Parse(userid), true),
                    new Permission(PermissionNames.Edit, int.Parse(userid), true)
                }.EncodePermissions();
                page.IsPersonalizable = false;
                page.UserId           = int.Parse(userid);
                page = _pages.AddPage(page);
                _syncManager.AddSyncEvent(_alias.TenantId, EntityNames.Site, page.SiteId);

                // copy modules
                List <PageModule> pagemodules = _pageModules.GetPageModules(page.SiteId).ToList();
                foreach (PageModule pm in pagemodules.Where(item => item.PageId == parent.PageId && !item.IsDeleted))
                {
                    Module module = new Module();
                    module.SiteId = page.SiteId;
                    module.PageId = page.PageId;
                    module.ModuleDefinitionName = pm.Module.ModuleDefinitionName;
                    module.AllPages             = false;
                    module.Permissions          = new List <Permission> {
                        new Permission(PermissionNames.View, int.Parse(userid), true),
                        new Permission(PermissionNames.Edit, int.Parse(userid), true)
                    }.EncodePermissions();
                    module = _modules.AddModule(module);

                    string content = _modules.ExportModule(pm.ModuleId);
                    if (content != "")
                    {
                        _modules.ImportModule(module.ModuleId, content);
                    }

                    PageModule pagemodule = new PageModule();
                    pagemodule.PageId        = page.PageId;
                    pagemodule.ModuleId      = module.ModuleId;
                    pagemodule.Title         = pm.Title;
                    pagemodule.Pane          = pm.Pane;
                    pagemodule.Order         = pm.Order;
                    pagemodule.ContainerType = pm.ContainerType;

                    _pageModules.AddPageModule(pagemodule);
                }
            }
            else
            {
                _logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Page Post Attempt {PageId} By User {UserId}", id, userid);
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
                page = null;
            }
            return(page);
        }