예제 #1
0
        public IEnumerable <Module> Get(string siteid)
        {
            List <Module> modulelist = new List <Module>();

            foreach (PageModule pagemodule in PageModules.GetPageModules(int.Parse(siteid)))
            {
                Module module = new Module();
                module.SiteId = pagemodule.Module.SiteId;
                module.ModuleDefinitionName = pagemodule.Module.ModuleDefinitionName;
                module.Permissions          = pagemodule.Module.Permissions;
                module.CreatedBy            = pagemodule.Module.CreatedBy;
                module.CreatedOn            = pagemodule.Module.CreatedOn;
                module.ModifiedBy           = pagemodule.Module.ModifiedBy;
                module.ModifiedOn           = pagemodule.Module.ModifiedOn;
                module.IsDeleted            = pagemodule.IsDeleted;

                module.PageModuleId  = pagemodule.PageModuleId;
                module.ModuleId      = pagemodule.ModuleId;
                module.PageId        = pagemodule.PageId;
                module.Title         = pagemodule.Title;
                module.Pane          = pagemodule.Pane;
                module.Order         = pagemodule.Order;
                module.ContainerType = pagemodule.ContainerType;
                modulelist.Add(module);
            }
            return(modulelist);
        }
예제 #2
0
 public Module Put(int id, [FromBody] Module Module)
 {
     if (ModelState.IsValid && UserPermissions.IsAuthorized(User, "Module", Module.ModuleId, "Edit"))
     {
         Module = Modules.UpdateModule(Module);
         logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Updated {Module}", Module);
     }
     return(Module);
 }
예제 #3
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);
 }
예제 #4
0
        public string Export(int moduleid)
        {
            string content = "";

            if (UserPermissions.IsAuthorized(User, "Module", moduleid, "View"))
            {
                try
                {
                    Module module = Modules.GetModule(moduleid);
                    if (module != null)
                    {
                        List <ModuleDefinition> moduledefinitions = ModuleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                        ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            ModuleContent modulecontent = new ModuleContent();
                            modulecontent.ModuleDefinitionName = moduledefinition.ModuleDefinitionName;
                            modulecontent.Version = moduledefinition.Version;
                            modulecontent.Content = "";

                            if (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);
                                        modulecontent.Content = ((IPortable)moduleobject).ExportModule(module);
                                    }
                                }
                            }
                            content = JsonSerializer.Serialize(modulecontent);
                            logger.Log(LogLevel.Information, this, LogFunction.Read, "Module Content Exported {ModuleId}", moduleid);
                        }
                    }
                }
                catch
                {
                    // error occurred during export
                }
            }
            return(content);
        }
예제 #5
0
        public bool Import(int moduleid, [FromBody] string Content)
        {
            bool success = false;

            if (ModelState.IsValid && UserPermissions.IsAuthorized(User, "Module", moduleid, "Edit"))
            {
                try
                {
                    Module module = Modules.GetModule(moduleid);
                    if (module != null)
                    {
                        List <ModuleDefinition> moduledefinitions = ModuleDefinitions.GetModuleDefinitions(module.SiteId).ToList();
                        ModuleDefinition        moduledefinition  = moduledefinitions.Where(item => item.ModuleDefinitionName == module.ModuleDefinitionName).FirstOrDefault();
                        if (moduledefinition != null)
                        {
                            ModuleContent modulecontent = JsonSerializer.Deserialize <ModuleContent>(Content);
                            if (modulecontent.ModuleDefinitionName == moduledefinition.ModuleDefinitionName)
                            {
                                if (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, modulecontent.Content, modulecontent.Version);
                                            success = true;
                                            logger.Log(LogLevel.Information, this, LogFunction.Update, "Module Content Imported {ModuleId}", moduleid);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    // error occurred during import
                }
            }
            return(success);
        }
예제 #6
0
        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
            });

            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)
                        {
                            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);
                        }
                    }
                }
            }
        }