private void BindItems() { // get settings SfBUser sfbUser = ES.Services.SfB.GetSfBUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID); // title litDisplayName.Text = sfbUser.DisplayName; planSelector.planId = sfbUser.SfBUserPlanId.ToString(); sfbUserSettings.sipAddress = sfbUser.SipAddress; Utils.SelectListItem(ddlPhoneNumber, sfbUser.LineUri); PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); OrganizationUser user = ES.Services.Organizations.GetUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID); if (user.LevelId > 0 && cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels)) { SolidCP.EnterpriseServer.Base.HostedSolution.ServiceLevel serviceLevel = ES.Services.Organizations.GetSupportServiceLevel(user.LevelId); litServiceLevel.Visible = true; litServiceLevel.Text = serviceLevel.LevelName; litServiceLevel.ToolTip = serviceLevel.LevelDescription; } imgVipUser.Visible = user.IsVIP && cntx.Groups.ContainsKey(ResourceGroups.ServiceLevels); }
protected void btnCreate_Click(object sender, EventArgs e) { int accountId = userSelector.GetAccountId(); SfBUserResult res = ES.Services.SfB.CreateSfBUser(PanelRequest.ItemID, accountId, Convert.ToInt32(planSelector.planId)); if (res.IsSuccess && res.ErrorCodes.Count == 0) { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); bool enterpriseVoiceQuota = Utils.CheckQouta(Quotas.SFB_ENTERPRISEVOICE, cntx); string lineUri = ""; if ((enterpriseVoiceQuota) & (ddlPhoneNumber.Items.Count != 0)) { lineUri = ddlPhoneNumber.SelectedItem.Text + ":" + tbPin.Text; } //#1 SfBUser sfbUser = ES.Services.SfB.GetSfBUserGeneralSettings(PanelRequest.ItemID, accountId); ES.Services.SfB.SetSfBUserGeneralSettings(PanelRequest.ItemID, accountId, sfbUser.SipAddress, lineUri); Response.Redirect(EditUrl("AccountID", accountId.ToString(), "edit_sfb_user", "SpaceID=" + PanelSecurity.PackageId, "ItemID=" + PanelRequest.ItemID)); } else { messageBox.ShowMessage(res, "CREATE_SFB_USER", "SFB"); } }
public bool SetSfBUserGeneralSettings(string organizationId, string userUpn, SfBUser sfbUser) { try { Log.WriteStart("{0}.SetSfBUserGeneralSettings", ProviderSettings.ProviderName); bool ret = SfB.SetSfBUserGeneralSettings(organizationId, userUpn, sfbUser); Log.WriteEnd("{0}.SetSfBUserGeneralSettings", ProviderSettings.ProviderName); return(ret); } catch (Exception ex) { Log.WriteError(String.Format("Error: {0}.SetSfBUserGeneralSettings", ProviderSettings.ProviderName), ex); throw; } }
public static SfBUser GetSfBUserGeneralSettings(int itemId, int accountId) { TaskManager.StartTask("SFB", "GET_SFB_USER_GENERAL_SETTINGS"); SfBUser user = null; try { Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) { throw new ApplicationException( string.Format("Organization is null. ItemId={0}", itemId)); } int sfbServiceId = GetSfBServiceID(org.PackageId); SfBServer sfb = GetSfBServer(sfbServiceId, org.ServiceId); OrganizationUser usr; usr = OrganizationController.GetAccount(itemId, accountId); if (usr != null) { user = sfb.GetSfBUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName); } if (user != null) { SfBUserPlan plan = ObjectUtils.FillObjectFromDataReader <SfBUserPlan>(DataProvider.GetSfBUserPlanByAccountId(accountId)); if (plan != null) { user.SfBUserPlanId = plan.SfBUserPlanId; user.SfBUserPlanName = plan.SfBUserPlanName; } } } catch (Exception ex) { throw TaskManager.WriteError(ex); } TaskManager.CompleteTask(); return(user); }
public static SfBUserResult SetSfBUserGeneralSettings(int itemId, int accountId, string sipAddress, string lineUri) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "SET_SFB_USER_GENERAL_SETTINGS"); string PIN = ""; string[] uriAndPin = ("" + lineUri).Split(':'); if (uriAndPin.Length > 0) { lineUri = uriAndPin[0]; } if (uriAndPin.Length > 1) { PIN = uriAndPin[1]; } SfBUser user = null; try { Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) { throw new ApplicationException( string.Format("Organization is null. ItemId={0}", itemId)); } int sfbServiceId = GetSfBServiceID(org.PackageId); SfBServer sfb = GetSfBServer(sfbServiceId, org.ServiceId); OrganizationUser usr; usr = OrganizationController.GetAccount(itemId, accountId); if (usr != null) { user = sfb.GetSfBUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName); } if (user != null) { SfBUserPlan plan = ObjectUtils.FillObjectFromDataReader <SfBUserPlan>(DataProvider.GetSfBUserPlanByAccountId(accountId)); if (plan != null) { user.SfBUserPlanId = plan.SfBUserPlanId; user.SfBUserPlanName = plan.SfBUserPlanName; } if (!string.IsNullOrEmpty(sipAddress)) { if (user.SipAddress != sipAddress) { if (sipAddress != usr.UserPrincipalName) { if (DataProvider.SfBUserExists(accountId, sipAddress)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.ADDRESS_ALREADY_USED); return(res); } } user.SipAddress = sipAddress; } } user.LineUri = lineUri; user.PIN = PIN; sfb.SetSfBUserGeneralSettings(org.OrganizationId, usr.UserPrincipalName, user); DataProvider.UpdateSfBUser(accountId, sipAddress); } } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.FAILED_SET_SETTINGS, ex); return(res); } res.IsSuccess = true; TaskManager.CompleteResultTask(); return(res); }
public static SfBUserResult CreateSfBUser(int itemId, int accountId, int sfbUserPlanId) { SfBUserResult res = TaskManager.StartResultTask <SfBUserResult>("SFB", "CREATE_SFB_USER"); int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { TaskManager.CompleteResultTask(res, SfBErrorCodes.NOT_AUTHORIZED); return(res); } SfBUser retSfBUser = new SfBUser(); bool isSfBUser; isSfBUser = DataProvider.CheckSfBUserExists(accountId); if (isSfBUser) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_IS_ALREADY_SFB_USER); return(res); } OrganizationUser user; user = OrganizationController.GetAccount(itemId, accountId); if (user == null) { TaskManager.CompleteResultTask(res, ErrorCodes.CANNOT_GET_ACCOUNT); return(res); } user = OrganizationController.GetUserGeneralSettings(itemId, accountId); if (string.IsNullOrEmpty(user.FirstName)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_FIRST_NAME_IS_NOT_SPECIFIED); return(res); } if (string.IsNullOrEmpty(user.LastName)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_LAST_NAME_IS_NOT_SPECIFIED); return(res); } bool quota = CheckQuota(itemId); if (!quota) { TaskManager.CompleteResultTask(res, SfBErrorCodes.USER_QUOTA_HAS_BEEN_REACHED); return(res); } SfBServer sfb; try { bool bReloadConfiguration = false; Organization org = (Organization)PackageController.GetPackageItem(itemId); if (org == null) { throw new ApplicationException( string.Format("Organization is null. ItemId={0}", itemId)); } int sfbServiceId = GetSfBServiceID(org.PackageId); sfb = GetSfBServer(sfbServiceId, org.ServiceId); if (string.IsNullOrEmpty(org.SfBTenantId)) { PackageContext cntx = PackageController.GetPackageContext(org.PackageId); org.SfBTenantId = sfb.CreateOrganization(org.OrganizationId, org.DefaultDomain, Convert.ToBoolean(cntx.Quotas[Quotas.SFB_CONFERENCING].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ALLOWVIDEO].QuotaAllocatedValue), Convert.ToInt32(cntx.Quotas[Quotas.SFB_MAXPARTICIPANTS].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_FEDERATION].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ENTERPRISEVOICE].QuotaAllocatedValue)); if (string.IsNullOrEmpty(org.SfBTenantId)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ENABLE_ORG); return(res); } else { DomainInfo domain = ServerController.GetDomain(org.DefaultDomain); //Add the service records if (domain != null) { if (domain.ZoneItemId != 0) { ServerController.AddServiceDNSRecords(org.PackageId, ResourceGroups.SfB, domain, ""); } } PackageController.UpdatePackageItem(org); bReloadConfiguration = true; } } if (sfb.GetOrganizationTenantId(org.OrganizationId) == string.Empty) { PackageContext cntx = PackageController.GetPackageContext(org.PackageId); org.SfBTenantId = sfb.CreateOrganization(org.OrganizationId, org.DefaultDomain, Convert.ToBoolean(cntx.Quotas[Quotas.SFB_CONFERENCING].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ALLOWVIDEO].QuotaAllocatedValue), Convert.ToInt32(cntx.Quotas[Quotas.SFB_MAXPARTICIPANTS].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_FEDERATION].QuotaAllocatedValue), Convert.ToBoolean(cntx.Quotas[Quotas.SFB_ENTERPRISEVOICE].QuotaAllocatedValue)); if (string.IsNullOrEmpty(org.SfBTenantId)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ENABLE_ORG); return(res); } else { PackageController.UpdatePackageItem(org); bReloadConfiguration = true; } } SfBUserPlan plan = GetSfBUserPlan(itemId, sfbUserPlanId); if (!sfb.CreateUser(org.OrganizationId, user.UserPrincipalName, plan)) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER); return(res); } if (bReloadConfiguration) { SfBControllerAsync userWorker = new SfBControllerAsync(); userWorker.SfBServiceId = sfbServiceId; userWorker.OrganizationServiceId = org.ServiceId; userWorker.Enable_CsComputerAsync(); } } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER, ex); return(res); } try { DataProvider.AddSfBUser(accountId, sfbUserPlanId, user.UserPrincipalName); } catch (Exception ex) { TaskManager.CompleteResultTask(res, SfBErrorCodes.CANNOT_ADD_SFB_USER_TO_DATABASE, ex); return(res); } res.IsSuccess = true; TaskManager.CompleteResultTask(); return(res); }