private void CreateSite(Site site) { // create default entities for 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\"}]" }); var _pageTemplates = CreateAdminPages(); CreatePages(site, _pageTemplates); // process site template if (string.IsNullOrEmpty(site.SiteTemplateType)) { var section = _config.GetSection("SiteTemplate"); if (section.Exists()) { site.SiteTemplateType = section.Value; } else { site.SiteTemplateType = Constants.DefaultSiteTemplate; } } Type siteTemplateType = Type.GetType(site.SiteTemplateType); if (siteTemplateType != null) { var siteTemplateObject = ActivatorUtilities.CreateInstance(_serviceProvider, siteTemplateType); List <PageTemplate> pageTemplates = ((ISiteTemplate)siteTemplateObject).CreateSite(site); if (pageTemplates != null && pageTemplates.Count > 0) { CreatePages(site, pageTemplates); } } }
private async Task <User> CreateUser(User user) { User newUser = null; bool verified; bool allowregistration; if (User.IsInRole(RoleNames.Admin)) { verified = true; allowregistration = true; } else { verified = false; allowregistration = _sites.GetSite(user.SiteId).AllowRegistration; } if (allowregistration) { IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username); if (identityuser == null) { identityuser = new IdentityUser(); identityuser.UserName = user.Username; identityuser.Email = user.Email; identityuser.EmailConfirmed = verified; var result = await _identityUserManager.CreateAsync(identityuser, user.Password); if (result.Succeeded) { user.LastLoginOn = null; user.LastIPAddress = ""; newUser = _users.AddUser(user); if (!verified) { string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser); string url = HttpContext.Request.Scheme + "://" + _alias.Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token); string body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!"; var notification = new Notification(user.SiteId, null, newUser, "User Account Verification", body, null); _notifications.AddNotification(notification); } // add folder for user Folder folder = _folders.GetFolder(user.SiteId, Utilities.PathCombine("Users", Path.DirectorySeparatorChar.ToString())); if (folder != null) { _folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Type = FolderTypes.Private, Path = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(), Path.DirectorySeparatorChar.ToString()), Order = 1, ImageSizes = "", Capacity = Constants.UserFolderCapacity, IsSystem = true, Permissions = new List <Permission> { new Permission(PermissionNames.Browse, newUser.UserId, true), new Permission(PermissionNames.View, RoleNames.Everyone, true), new Permission(PermissionNames.Edit, newUser.UserId, true) }.EncodePermissions() }); } } } else { var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false); if (result.Succeeded) { newUser = _users.GetUser(user.Username); } } if (newUser != null) { // add auto assigned roles to user for site List <Role> roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList(); foreach (Role role in roles) { UserRole userrole = new UserRole(); userrole.UserId = newUser.UserId; userrole.RoleId = role.RoleId; userrole.EffectiveDate = null; userrole.ExpiryDate = null; _userRoles.AddUserRole(userrole); } } if (newUser != null) { newUser.Password = ""; // remove sensitive information _logger.Log(user.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", newUser); } } else { _logger.Log(user.SiteId, LogLevel.Error, this, LogFunction.Create, "User Registration Is Not Enabled For Site. User Was Not Added {User}", user); } return(newUser); }
//TODO shoud be moved to another layer private async Task <User> CreateUser(User user) { User newUser = null; bool verified; bool allowregistration; if (user.Username == Constants.HostUser || User.IsInRole(Constants.AdminRole)) { verified = true; allowregistration = true; } else { verified = false; allowregistration = _sites.GetSite(user.SiteId).AllowRegistration; } if (allowregistration) { IdentityUser identityuser = await _identityUserManager.FindByNameAsync(user.Username); if (identityuser == null) { identityuser = new IdentityUser(); identityuser.UserName = user.Username; identityuser.Email = user.Email; identityuser.EmailConfirmed = verified; var result = await _identityUserManager.CreateAsync(identityuser, user.Password); if (result.Succeeded) { user.LastLoginOn = null; user.LastIPAddress = ""; newUser = _users.AddUser(user); if (!verified) { Notification notification = new Notification(); notification.SiteId = user.SiteId; notification.FromUserId = null; notification.ToUserId = newUser.UserId; notification.ToEmail = ""; notification.Subject = "User Account Verification"; string token = await _identityUserManager.GenerateEmailConfirmationTokenAsync(identityuser); string url = HttpContext.Request.Scheme + "://" + _tenants.GetAlias().Name + "/login?name=" + user.Username + "&token=" + WebUtility.UrlEncode(token); notification.Body = "Dear " + user.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!"; notification.ParentId = null; notification.CreatedOn = DateTime.UtcNow; notification.IsDelivered = false; notification.DeliveredOn = null; _notifications.AddNotification(notification); } // assign to host role if this is the host user ( initial installation ) if (user.Username == Constants.HostUser) { int hostroleid = _roles.GetRoles(user.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId; UserRole userrole = new UserRole(); userrole.UserId = newUser.UserId; userrole.RoleId = hostroleid; userrole.EffectiveDate = null; userrole.ExpiryDate = null; _userRoles.AddUserRole(userrole); } // add folder for user Folder folder = _folders.GetFolder(user.SiteId, Utilities.PathCombine("Users", "\\")); if (folder != null) { _folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Path = Utilities.PathCombine(folder.Path, newUser.UserId.ToString(), "\\"), Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"}]" }); } } } else { var result = await _identitySignInManager.CheckPasswordSignInAsync(identityuser, user.Password, false); if (result.Succeeded) { newUser = _users.GetUser(user.Username); } } if (newUser != null && user.Username != Constants.HostUser) { // add auto assigned roles to user for site List <Role> roles = _roles.GetRoles(user.SiteId).Where(item => item.IsAutoAssigned).ToList(); foreach (Role role in roles) { UserRole userrole = new UserRole(); userrole.UserId = newUser.UserId; userrole.RoleId = role.RoleId; userrole.EffectiveDate = null; userrole.ExpiryDate = null; _userRoles.AddUserRole(userrole); } } if (newUser != null) { newUser.Password = ""; // remove sensitive information _logger.Log(user.SiteId, LogLevel.Information, this, LogFunction.Create, "User Added {User}", newUser); } } else { _logger.Log(user.SiteId, LogLevel.Error, this, LogFunction.Create, "User Registration Is Not Enabled For Site. User Was Not Added {User}", user); } return(newUser); }
public async Task <User> Post([FromBody] User User) { User user = null; if (ModelState.IsValid) { bool verified = true; // users created by non-administrators must be verified if (!base.User.IsInRole(Constants.AdminRole) && User.Username != Constants.HostUser) { verified = false; } IdentityUser identityuser = await IdentityUserManager.FindByNameAsync(User.Username); if (identityuser == null) { identityuser = new IdentityUser(); identityuser.UserName = User.Username; identityuser.Email = User.Email; identityuser.EmailConfirmed = verified; var result = await IdentityUserManager.CreateAsync(identityuser, User.Password); if (result.Succeeded) { User.LastLoginOn = null; User.LastIPAddress = ""; user = Users.AddUser(User); if (!verified) { Notification notification = new Notification(); notification.SiteId = User.SiteId; notification.FromUserId = null; notification.ToUserId = user.UserId; notification.ToEmail = ""; notification.Subject = "User Account Verification"; string token = await IdentityUserManager.GenerateEmailConfirmationTokenAsync(identityuser); string url = HttpContext.Request.Scheme + "://" + Tenants.GetAlias().Name + "/login?name=" + User.Username + "&token=" + WebUtility.UrlEncode(token); notification.Body = "Dear " + User.DisplayName + ",\n\nIn Order To Complete The Registration Of Your User Account Please Click The Link Displayed Below:\n\n" + url + "\n\nThank You!"; notification.ParentId = null; notification.CreatedOn = DateTime.Now; notification.IsDelivered = false; notification.DeliveredOn = null; Notifications.AddNotification(notification); } // assign to host role if this is the host user ( initial installation ) if (User.Username == Constants.HostUser) { int hostroleid = Roles.GetRoles(User.SiteId, true).Where(item => item.Name == Constants.HostRole).FirstOrDefault().RoleId; UserRole userrole = new UserRole(); userrole.UserId = user.UserId; userrole.RoleId = hostroleid; userrole.EffectiveDate = null; userrole.ExpiryDate = null; UserRoles.AddUserRole(userrole); } // add folder for user Folder folder = Folders.GetFolder(User.SiteId, "Users\\"); if (folder != null) { Folders.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", Path = folder.Path + user.UserId.ToString() + "\\", Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + user.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + user.UserId.ToString() + "]\"}]" }); } } } else { var result = await IdentitySignInManager.CheckPasswordSignInAsync(identityuser, User.Password, false); if (result.Succeeded) { user = Users.GetUser(User.Username); } } if (user != null && User.Username != Constants.HostUser) { // add auto assigned roles to user for site List <Role> roles = Roles.GetRoles(User.SiteId).Where(item => item.IsAutoAssigned == true).ToList(); foreach (Role role in roles) { UserRole userrole = new UserRole(); userrole.UserId = user.UserId; userrole.RoleId = role.RoleId; userrole.EffectiveDate = null; userrole.ExpiryDate = null; UserRoles.AddUserRole(userrole); } } user.Password = ""; // remove sensitive information logger.Log(LogLevel.Information, this, LogFunction.Create, "User Added {User}", user); } return(user); }
private void CreateSite(Site site) { // create default entities for site List <Role> roles = _roleRepository.GetRoles(site.SiteId, true).ToList(); if (!roles.Where(item => item.Name == RoleNames.Everyone).Any()) { _roleRepository.AddRole(new Role { SiteId = null, Name = RoleNames.Everyone, Description = "All Users", IsAutoAssigned = false, IsSystem = true }); } if (!roles.Where(item => item.Name == RoleNames.Host).Any()) { _roleRepository.AddRole(new Role { SiteId = null, Name = RoleNames.Host, Description = "Application Administrators", IsAutoAssigned = false, IsSystem = true }); } _roleRepository.AddRole(new Role { SiteId = site.SiteId, Name = RoleNames.Registered, Description = "Registered Users", IsAutoAssigned = true, IsSystem = true }); _roleRepository.AddRole(new Role { SiteId = site.SiteId, Name = RoleNames.Admin, 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 = new List <Permission> { new Permission(PermissionNames.Browse, RoleNames.Admin, true), new Permission(PermissionNames.View, RoleNames.Everyone, true), new Permission(PermissionNames.Edit, RoleNames.Admin, true) }.EncodePermissions() }); _folderRepository.AddFolder(new Folder { SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = Utilities.PathCombine("Users", Path.DirectorySeparatorChar.ToString()), Order = 1, IsSystem = true, Permissions = new List <Permission> { new Permission(PermissionNames.Browse, RoleNames.Admin, true), new Permission(PermissionNames.View, RoleNames.Admin, true), new Permission(PermissionNames.Edit, RoleNames.Admin, true) }.EncodePermissions() }); // process site template first if (string.IsNullOrEmpty(site.SiteTemplateType)) { var section = _config.GetSection("Installation:SiteTemplate"); if (section.Exists()) { if (string.IsNullOrEmpty(section.Value)) { site.SiteTemplateType = Constants.DefaultSiteTemplate; } else { site.SiteTemplateType = section.Value; } } else { site.SiteTemplateType = Constants.DefaultSiteTemplate; } } Type siteTemplateType = Type.GetType(site.SiteTemplateType); if (siteTemplateType != null) { var siteTemplateObject = ActivatorUtilities.CreateInstance(_serviceProvider, siteTemplateType); List <PageTemplate> pageTemplates = ((ISiteTemplate)siteTemplateObject).CreateSite(site); if (pageTemplates != null && pageTemplates.Count > 0) { CreatePages(site, pageTemplates); } } // create admin pages CreatePages(site, CreateAdminPages()); }
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, ImageHeight = 80, ImageWidth = 250 }); 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); } } } } }