Exemplo n.º 1
0
        private async Task DeleteSite(Alias alias)
        {
            try
            {
                if (alias.SiteId != PageState.Site.SiteId || alias.TenantId != PageState.Site.TenantId)
                {
                    SiteService.SetAlias(alias);
                    await SiteService.DeleteSiteAsync(alias.SiteId);
                    await Log(alias, LogLevel.Information, "", null, "Site Deleted {SiteId}", alias.SiteId);

                    var aliases = await AliasService.GetAliasesAsync();

                    foreach (Alias a in aliases.Where(item => item.SiteId == alias.SiteId && item.TenantId == alias.TenantId))
                    {
                        await AliasService.DeleteAliasAsync(a.AliasId);
                    }

                    NavigationManager.NavigateTo(NavigateUrl());
                }
                else
                {
                    AddModuleMessage("You Can Not Delete The Current Site", MessageType.Warning);
                }
            }
            catch (Exception ex)
            {
                await Log(alias, LogLevel.Error, "", ex, "Error Deleting Site {SiteId} {Error}", alias.SiteId, ex.Message);

                AddModuleMessage("Error Deleting Site", MessageType.Error);
            }
        }
Exemplo n.º 2
0
        private async Task DeleteTenant(Tenant Tenant)
        {
            try
            {
                string message = string.Empty;
                var    aliases = await AliasService.GetAliasesAsync();

                foreach (var alias in aliases)
                {
                    if (alias.TenantId == Tenant.TenantId)
                    {
                        message += ", " + alias.Name;
                    }
                }
                if (string.IsNullOrEmpty(message))
                {
                    await TenantService.DeleteTenantAsync(Tenant.TenantId);

                    await logger.LogInformation("Tenant Deleted {Tenant}", Tenant);

                    StateHasChanged();
                }
                else
                {
                    AddModuleMessage("Tenant Cannot Be Deleted Until The Following Sites Are Deleted: " + message.Substring(2), MessageType.Warning);
                }
            }
            catch (Exception ex)
            {
                await logger.LogError(ex, "Error Deleting Tenant {Tenant} {Error}", Tenant, ex.Message);

                AddModuleMessage("Error Deleting Tenant", MessageType.Error);
            }
        }
Exemplo n.º 3
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                _themeList = await ThemeService.GetThemesAsync();

                _aliasList = await AliasService.GetAliasesAsync();

                _alias = _aliasList.Find(item => item.AliasId == Int32.Parse(PageState.QueryString["id"]));
                SiteService.SetAlias(_alias);
                var site = await SiteService.GetSiteAsync(_alias.SiteId);

                if (site != null)
                {
                    _name       = site.Name;
                    _tenantList = await TenantService.GetTenantsAsync();

                    _tenant = _tenantList.Find(item => item.TenantId == site.TenantId).Name;

                    foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
                    {
                        _urls += alias.Name + "\n";
                    }

                    _themes        = ThemeService.GetThemeControls(_themeList);
                    _themetype     = site.DefaultThemeType;
                    _layouts       = ThemeService.GetLayoutControls(_themeList, _themetype);
                    _layouttype    = site.DefaultLayoutType;
                    _containers    = ThemeService.GetContainerControls(_themeList, _themetype);
                    _containertype = site.DefaultContainerType;
                    _createdby     = site.CreatedBy;
                    _createdon     = site.CreatedOn;
                    _modifiedby    = site.ModifiedBy;
                    _modifiedon    = site.ModifiedOn;
                    _deletedby     = site.DeletedBy;
                    _deletedon     = site.DeletedOn;
                    _isdeleted     = site.IsDeleted.ToString();

                    _initialized = true;
                }
            }
            catch (Exception ex)
            {
                await Log(_alias, LogLevel.Error, string.Empty, ex, "Error Loading Site {SiteId} {Error}", _alias.SiteId, ex.Message);

                AddModuleMessage(ex.Message, MessageType.Error);
            }
        }
Exemplo n.º 4
0
        protected override async Task OnParametersSetAsync()
        {
            var uri = new Uri(NavigationManager.Uri);

            _scheme = uri.Scheme + "://";

            var aliases = await AliasService.GetAliasesAsync();

            _sites = new List <Alias>();
            foreach (Alias alias in aliases)
            {
                if (!_sites.Exists(item => item.TenantId == alias.TenantId && item.SiteId == alias.SiteId))
                {
                    _sites.Add(alias);
                }
            }
        }
Exemplo n.º 5
0
        protected override async Task OnInitializedAsync()
        {
            try
            {
                _themeList = await ThemeService.GetThemesAsync();

                _aliasList = await AliasService.GetAliasesAsync();

                Site site = await SiteService.GetSiteAsync(PageState.Site.SiteId);

                if (site != null)
                {
                    _name       = site.Name;
                    _tenantList = await TenantService.GetTenantsAsync();

                    _tenant = _tenantList.Find(item => item.TenantId == site.TenantId).Name;
                    foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList())
                    {
                        _urls += alias.Name + "\n";
                    }
                    if (site.LogoFileId != null)
                    {
                        _logofileid = site.LogoFileId.Value;
                    }

                    if (site.FaviconFileId != null)
                    {
                        _faviconfileid = site.FaviconFileId.Value;
                    }

                    _themes            = ThemeService.GetThemeControls(_themeList);
                    _themetype         = site.DefaultThemeType;
                    _layouts           = ThemeService.GetLayoutControls(_themeList, _themetype);
                    _layouttype        = site.DefaultLayoutType;
                    _containers        = ThemeService.GetContainerControls(_themeList, _themetype);
                    _containertype     = site.DefaultContainerType;
                    _allowregistration = site.AllowRegistration.ToString();

                    var settings = await SettingService.GetSiteSettingsAsync(site.SiteId);

                    _smtphost     = SettingService.GetSetting(settings, "SMTPHost", string.Empty);
                    _smtpport     = SettingService.GetSetting(settings, "SMTPPort", string.Empty);
                    _smtpssl      = SettingService.GetSetting(settings, "SMTPSSL", string.Empty);
                    _smtpusername = SettingService.GetSetting(settings, "SMTPUsername", string.Empty);
                    _smtppassword = SettingService.GetSetting(settings, "SMTPPassword", string.Empty);

                    _pwaisenabled = site.PwaIsEnabled.ToString();

                    if (site.PwaAppIconFileId != null)
                    {
                        _pwaappiconfileid = site.PwaAppIconFileId.Value;
                    }

                    if (site.PwaSplashIconFileId != null)
                    {
                        _pwasplashiconfileid = site.PwaSplashIconFileId.Value;
                    }

                    _pwaisenabled = site.PwaIsEnabled.ToString();
                    if (site.PwaAppIconFileId != null)
                    {
                        _pwaappiconfileid = site.PwaAppIconFileId.Value;
                    }
                    if (site.PwaSplashIconFileId != null)
                    {
                        _pwasplashiconfileid = site.PwaSplashIconFileId.Value;
                    }

                    _createdby  = site.CreatedBy;
                    _createdon  = site.CreatedOn;
                    _modifiedby = site.ModifiedBy;
                    _modifiedon = site.ModifiedOn;
                    _deletedby  = site.DeletedBy;
                    _deletedon  = site.DeletedOn;
                    _isdeleted  = site.IsDeleted.ToString();

                    _initialized = true;
                }
            }
            catch (Exception ex)
            {
                await logger.LogError(ex, "Error Loading Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message);

                AddModuleMessage(ex.Message, MessageType.Error);
            }
        }
Exemplo n.º 6
0
        private async Task SaveSite()
        {
            if (_tenantid != "-" && _name != string.Empty && _urls != string.Empty && _themetype != "-" && (_layouts.Count == 0 || _layouttype != "-") && _containertype != "-" && _sitetemplatetype != "-")
            {
                var duplicates = new List <string>();
                var aliases    = await AliasService.GetAliasesAsync();

                foreach (string name in _urls.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (aliases.Exists(item => item.Name == name))
                    {
                        duplicates.Add(name);
                    }
                }

                if (duplicates.Count == 0)
                {
                    InstallConfig config = new InstallConfig();

                    if (_tenantid == "+")
                    {
                        if (!string.IsNullOrEmpty(_tenantname) && _tenants.FirstOrDefault(item => item.Name == _tenantname) == null)
                        {
                            // validate host credentials
                            var user = new User();
                            user.SiteId   = PageState.Site.SiteId;
                            user.Username = Constants.HostUser;
                            user.Password = _hostpassword;
                            user          = await UserService.LoginUserAsync(user, false, false);

                            if (user.IsAuthenticated)
                            {
                                if (!string.IsNullOrEmpty(_server) && !string.IsNullOrEmpty(_database))
                                {
                                    var connectionString = string.Empty;
                                    if (_databasetype == "LocalDB")
                                    {
                                        connectionString = "Data Source=" + _server + ";AttachDbFilename=|DataDirectory|\\" + _database + ".mdf;Initial Catalog=" + _database + ";Integrated Security=SSPI;";
                                    }
                                    else
                                    {
                                        connectionString = "Data Source=" + _server + ";Initial Catalog=" + _database + ";";

                                        if (_integratedsecurity)
                                        {
                                            connectionString += "Integrated Security=SSPI;";
                                        }
                                        else
                                        {
                                            connectionString += "User ID=" + _username + ";Password="******"You Must Specify A Server And Database", MessageType.Error);
                                }
                            }
                            else
                            {
                                AddModuleMessage("Invalid Host Password", MessageType.Error);
                            }
                        }
                        else
                        {
                            AddModuleMessage("Tenant Name Is Missing Or Already Exists", MessageType.Error);
                        }
                    }
                    else
                    {
                        var tenant = _tenants.FirstOrDefault(item => item.TenantId == int.Parse(_tenantid));
                        if (tenant != null)
                        {
                            config.TenantName       = tenant.Name;
                            config.ConnectionString = tenant.DBConnectionString;
                            config.IsNewTenant      = false;
                        }
                    }

                    if (!string.IsNullOrEmpty(config.TenantName))
                    {
                        config.SiteName         = _name;
                        config.Aliases          = _urls.Replace("\n", ",");
                        config.DefaultTheme     = _themetype;
                        config.DefaultLayout    = _layouttype;
                        config.DefaultContainer = _containertype;
                        config.SiteTemplate     = _sitetemplatetype;

                        ShowProgressIndicator();

                        var installation = await InstallationService.Install(config);

                        if (installation.Success)
                        {
                            var aliasname = config.Aliases.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0];
                            var uri       = new Uri(NavigationManager.Uri);
                            NavigationManager.NavigateTo(uri.Scheme + "://" + aliasname, true);
                        }
                        else
                        {
                            await logger.LogError("Error Creating Site {Error}", installation.Message);

                            AddModuleMessage(installation.Message, MessageType.Error);
                        }
                    }
                }
                else
                {
                    AddModuleMessage(string.Join(", ", duplicates.ToArray()) + " Already Used For Another Site", MessageType.Warning);
                }
            }
            else
            {
                AddModuleMessage("You Must Provide A Tenant, Site Name, Alias, Default Theme/Container, And Site Template", MessageType.Warning);
            }
        }