private IActionResult CheckExistingNamePortal(string portalName) { if (string.IsNullOrEmpty(portalName)) { return(BadRequest(new { error = "portalNameEmpty" })); } try { if (!string.IsNullOrEmpty(ApiSystemHelper.ApiCacheUrl)) { ValidateDomain(portalName.Trim()); } else { HostedSolution.CheckTenantAddress(portalName.Trim()); } } catch (TenantAlreadyExistsException ex) { return(BadRequest(new { errors = new[] { "portalNameExist" }, variants = ex.ExistsTenants.ToArray() })); } catch (TenantTooShortException) { return(BadRequest(new { errors = new[] { "tooShortError" } })); } catch (TenantIncorrectCharsException) { return(BadRequest(new { errors = new[] { "portalNameIncorrect" } })); } catch (Exception ex) { Log.Error(ex); return(StatusCode(StatusCodes.Status500InternalServerError, new { errors = new[] { "error" }, message = ex.Message, stacktrace = ex.StackTrace })); } return(null); }
private bool CheckExistingNamePortal(string portalName, out object error) { error = null; if (string.IsNullOrEmpty(portalName)) { error = new { error = "portalNameEmpty", message = "PortalName is required" }; return false; } try { if (!string.IsNullOrEmpty(ApiSystemHelper.ApiCacheUrl)) { ValidateDomain(portalName.Trim()); } else { HostedSolution.CheckTenantAddress(portalName.Trim()); } } catch (TenantAlreadyExistsException ex) { error = new { error = "portalNameExist", message = "Portal already exists", variants = ex.ExistsTenants.ToArray() }; return false; } catch (TenantTooShortException) { error = new { error = "tooShortError", message = "Portal name is too short" }; return false; } catch (TenantIncorrectCharsException) { error = new { error = "portalNameIncorrect", message = "Unallowable symbols in portalName" }; return false; } catch (Exception ex) { Log.Error(ex); error = new { error = "error", message = ex.Message, stacktrace = ex.StackTrace }; return false; } return true; }
public object UpdatePortalName(string alias) { var enabled = SetupInfo.IsVisibleSettings("PortalRename"); if (!enabled) { throw new SecurityException(Resource.PortalAccessSettingsTariffException); } if (CoreContext.Configuration.Personal) { throw new Exception(Resource.ErrorAccessDenied); } SecurityContext.DemandPermissions(SecutiryConstants.EditPortalSettings); if (String.IsNullOrEmpty(alias)) { throw new ArgumentException(); } var tenant = CoreContext.TenantManager.GetCurrentTenant(); var user = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID); var newAlias = alias.ToLowerInvariant(); var oldAlias = tenant.TenantAlias; var oldVirtualRootPath = CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'); if (!String.Equals(newAlias, oldAlias, StringComparison.InvariantCultureIgnoreCase)) { var hostedSolution = new HostedSolution(ConfigurationManager.ConnectionStrings["default"]); if (!String.IsNullOrEmpty(ApiSystemHelper.ApiSystemUrl)) { ApiSystemHelper.ValidatePortalName(newAlias); } else { hostedSolution.CheckTenantAddress(newAlias.Trim()); } if (!String.IsNullOrEmpty(ApiSystemHelper.ApiCacheUrl)) { ApiSystemHelper.AddTenantToCache(newAlias); } tenant.TenantAlias = alias; tenant = hostedSolution.SaveTenant(tenant); if (!String.IsNullOrEmpty(ApiSystemHelper.ApiCacheUrl)) { ApiSystemHelper.RemoveTenantFromCache(oldAlias); } var newVirtualRootPath = CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'); if (!string.Equals(oldVirtualRootPath, newVirtualRootPath, StringComparison.InvariantCultureIgnoreCase)) { StudioNotifyService.Instance.PortalRenameNotify(oldVirtualRootPath); } } else { throw new Exception(ResourceJS.ErrorPortalNameWasNotChanged); } var reference = CreateReference(Request, tenant.TenantDomain, tenant.TenantId, user.Email); return(new { message = Resource.SuccessfullyPortalRenameMessage, reference = reference }); }