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); } }
private async Task SaveSite() { try { if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && (_layouts.Count == 0 || _layouttype != "-") && _containertype != "-") { var unique = true; foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (_aliasList.Exists(item => item.Name == name && item.SiteId != _alias.SiteId && item.TenantId != _alias.TenantId)) { unique = false; } } if (unique) { SiteService.SetAlias(_alias); var site = await SiteService.GetSiteAsync(_alias.SiteId); if (site != null) { site.Name = _name; site.LogoFileId = null; site.DefaultThemeType = _themetype; site.DefaultLayoutType = _layouttype ?? string.Empty; site.DefaultContainerType = _containertype; site.IsDeleted = (_isdeleted == null || Boolean.Parse(_isdeleted)); site = await SiteService.UpdateSiteAsync(site); _urls = _urls.Replace("\n", ","); var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) { if (!names.Contains(alias.Name)) { await AliasService.DeleteAliasAsync(alias.AliasId); } } foreach (string name in names) { if (!_aliasList.Exists(item => item.Name == name)) { Alias alias = new Alias { Name = name, TenantId = site.TenantId, SiteId = site.SiteId }; await AliasService.AddAliasAsync(alias); } } await Log(_alias, LogLevel.Information, PermissionNames.Edit, null, "Site Saved {Site}", site); NavigationManager.NavigateTo(NavigateUrl()); } } else { AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning); } } else { AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning); } } catch (Exception ex) { await Log(_alias, LogLevel.Error, string.Empty, ex, "Error Saving Site {SiteId} {Error}", _alias.SiteId, ex.Message); AddModuleMessage("Error Saving Site", MessageType.Error); } }
private async Task SaveSite() { try { if (_name != string.Empty && _urls != string.Empty && _themetype != "-" && (_layouts.Count == 0 || _layouttype != "-") && _containertype != "-") { var unique = true; foreach (string name in _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { if (_aliasList.Exists(item => item.Name == name && item.SiteId != PageState.Alias.SiteId && item.TenantId != PageState.Alias.TenantId)) { unique = false; } } if (unique) { var site = await SiteService.GetSiteAsync(PageState.Site.SiteId); if (site != null) { site.Name = _name; site.LogoFileId = null; var logofileid = _logofilemanager.GetFileId(); if (logofileid != -1) { site.LogoFileId = logofileid; } site.DefaultThemeType = _themetype; site.DefaultLayoutType = (_layouttype == "-" ? string.Empty : _layouttype); site.DefaultContainerType = _containertype; site.AllowRegistration = (_allowregistration == null ? true : Boolean.Parse(_allowregistration)); site.IsDeleted = (_isdeleted == null ? true : Boolean.Parse(_isdeleted)); site.PwaIsEnabled = (_pwaisenabled == null ? true : Boolean.Parse(_pwaisenabled)); var pwaappiconfileid = _pwaappiconfilemanager.GetFileId(); if (pwaappiconfileid != -1) { site.PwaAppIconFileId = pwaappiconfileid; } var pwasplashiconfileid = _pwasplashiconfilemanager.GetFileId(); if (pwasplashiconfileid != -1) { site.PwaSplashIconFileId = pwasplashiconfileid; } site = await SiteService.UpdateSiteAsync(site); _urls = _urls.Replace("\n", ","); var names = _urls.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (Alias alias in _aliasList.Where(item => item.SiteId == site.SiteId && item.TenantId == site.TenantId).ToList()) { if (!names.Contains(alias.Name)) { await AliasService.DeleteAliasAsync(alias.AliasId); } } foreach (string name in names) { if (!_aliasList.Exists(item => item.Name == name)) { Alias alias = new Alias(); alias.Name = name; alias.TenantId = site.TenantId; alias.SiteId = site.SiteId; await AliasService.AddAliasAsync(alias); } } var settings = await SettingService.GetSiteSettingsAsync(site.SiteId); SettingService.SetSetting(settings, "SMTPHost", _smtphost); SettingService.SetSetting(settings, "SMTPPort", _smtpport); SettingService.SetSetting(settings, "SMTPSSL", _smtpssl); SettingService.SetSetting(settings, "SMTPUsername", _smtpusername); SettingService.SetSetting(settings, "SMTPPassword", _smtppassword); await SettingService.UpdateSiteSettingsAsync(settings, site.SiteId); await logger.LogInformation("Site Saved {Site}", site); NavigationManager.NavigateTo(NavigateUrl()); } } else { AddModuleMessage("An Alias Specified Has Already Been Used For Another Site", MessageType.Warning); } } else { AddModuleMessage("You Must Provide A Site Name, Alias, And Default Theme/Container", MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving Site {SiteId} {Error}", PageState.Site.SiteId, ex.Message); AddModuleMessage("Error Saving Site", MessageType.Error); } }