public IActionResult ChangeStatus(TenantModel model, bool active) { if (model == null) { return(BadRequest(new { errors = "PortalName is required." })); } var tenant = HostedSolution.GetTenant((model.PortalName ?? "").Trim()); if (tenant == null) { return(BadRequest(new { errors = "Tenant not found." })); } tenant.SetStatus(active ? TenantStatus.Active : TenantStatus.Suspended); HostedSolution.SaveTenant(tenant); return(Ok(new { errors = "", tenant = ToTenantWrapper(tenant) })); }
public IActionResult ChangeStatus(TenantModel model) { if (!CommonMethods.GetTenant(model, out var tenant)) { Log.Error("Model without tenant"); return BadRequest(new { error = "portalNameEmpty", message = "PortalName is required" }); } if (tenant == null) { Log.Error("Tenant not found"); return BadRequest(new { error = "portalNameNotFound", message = "Portal not found" }); } var active = model.Status; if (active != TenantStatus.Active) { active = TenantStatus.Suspended; } tenant.SetStatus(active); HostedSolution.SaveTenant(tenant); return Ok(new { tenant = CommonMethods.ToTenantWrapper(tenant) }); }
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 }); }