public static ResultObject ChangeUserState(int itemId, int accountId, bool disable) { CrmRolesResult res = StartTask <CrmRolesResult>("CRM", "CHANGER_USER_STATE"); Organization org; try { try { org = OrganizationController.GetOrganization(itemId); if (org == null) { throw new ApplicationException("Org is null."); } } catch (Exception ex) { CompleteTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex); return(res); } int serviceId = PackageController.GetPackageServiceId(org.PackageId, ResourceGroups.HostedCRM); if (serviceId == 0) { CompleteTask(res, CrmErrorCodes.CRM_IS_NOT_SELECTED_IN_HOSTING_PLAN, null, "CRM is not selected in hosting plan."); return(res); } CRM crm = new CRM(); ServiceProviderProxy.Init(crm, serviceId); Guid crmUserId = GetCrmUserId(accountId); ResultObject changeStateRes = crm.ChangeUserState(disable, org.OrganizationId, crmUserId); if (!changeStateRes.IsSuccess) { res.IsSuccess = false; } res.ErrorCodes.AddRange(changeStateRes.ErrorCodes); } catch (Exception ex) { CompleteTask(res, CrmErrorCodes.CANNOT_CHANGE_USER_STATE_GENERAL_ERROR, ex); return(res); } CompleteTask(); return(res); }
public static ResultObject SetUserRoles(int itemId, int accountId, int packageId, Guid[] roles) { CrmRolesResult res = StartTask <CrmRolesResult>("CRM", "GET_CRM_ROLES"); try { int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedCRM); if (serviceId == 0) { CompleteTask(res, CrmErrorCodes.CRM_IS_NOT_SELECTED_IN_HOSTING_PLAN, null, "CRM is not selected in hosting plan."); return(res); } CRM crm = new CRM(); ServiceProviderProxy.Init(crm, serviceId); Organization org; try { org = OrganizationController.GetOrganization(itemId); if (org == null) { throw new ApplicationException("Org is null."); } } catch (Exception ex) { CompleteTask(res, ErrorCodes.CANNOT_GET_ORGANIZATION_BY_ITEM_ID, ex); return(res); } Guid crmUserId = GetCrmUserId(accountId); ResultObject rolesRes = crm.SetUserRoles(org.OrganizationId, crmUserId, roles); res.ErrorCodes.AddRange(rolesRes.ErrorCodes); if (!rolesRes.IsSuccess) { CompleteTask(res); return(res); } } catch (Exception ex) { CompleteTask(res, CrmErrorCodes.CANNOT_SET_CRM_USER_ROLES_GENERAL_ERROR, ex); return(res); } CompleteTask(); return(res); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { OrganizationUser user = ES.Services.Organizations.GetUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID); CrmUserResult userResult = ES.Services.CRM.GetCrmUser(PanelRequest.ItemID, PanelRequest.AccountID); if (userResult.IsSuccess) { btnActive.Visible = userResult.Value.IsDisabled; locEnabled.Visible = !userResult.Value.IsDisabled; btnDeactivate.Visible = !userResult.Value.IsDisabled; locDisabled.Visible = userResult.Value.IsDisabled; lblDisplayName.Text = user.DisplayName; lblEmailAddress.Text = user.PrimaryEmailAddress; lblDomainName.Text = user.DomainUserName; } else { messageBox.ShowMessage(userResult, "GET_CRM_USER", "HostedCRM"); return; } CrmRolesResult res = ES.Services.CRM.GetCrmRoles(PanelRequest.ItemID, PanelRequest.AccountID, PanelSecurity.PackageId); if (res.IsSuccess) { gvRoles.DataSource = res.Value; gvRoles.DataBind(); } else { messageBox.ShowMessage(res, "GET_CRM_USER_ROLES", "HostedCRM"); } } catch (Exception ex) { messageBox.ShowErrorMessage("GET_CRM_USER_ROLES", ex); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { PackageContext cntx = PackagesHelper.GetCachedPackageContext(PanelSecurity.PackageId); if (cntx.Groups.ContainsKey(ResourceGroups.HostedCRM2013)) { ddlLicenseType.Items.Add(new System.Web.UI.WebControls.ListItem( GetSharedLocalizedString("HostedCRM.LicenseProfessional"), CRMUserLycenseTypes.PROFESSIONAL.ToString())); ddlLicenseType.Items.Add(new System.Web.UI.WebControls.ListItem( GetSharedLocalizedString("HostedCRM.LicenseBasic"), CRMUserLycenseTypes.BASIC.ToString())); ddlLicenseType.Items.Add(new System.Web.UI.WebControls.ListItem( GetSharedLocalizedString("HostedCRM.LicenseEssential"), CRMUserLycenseTypes.ESSENTIAL.ToString())); } else { ddlLicenseType.Items.Add(new System.Web.UI.WebControls.ListItem( GetSharedLocalizedString("HostedCRM.LicenseFull"), CRMUserLycenseTypes.FULL.ToString())); ddlLicenseType.Items.Add(new System.Web.UI.WebControls.ListItem( GetSharedLocalizedString("HostedCRM.LicenseLimited"), CRMUserLycenseTypes.LIMITED.ToString())); ddlLicenseType.Items.Add(new System.Web.UI.WebControls.ListItem( GetSharedLocalizedString("HostedCRM.LicenseESS"), CRMUserLycenseTypes.ESS.ToString())); } try { OrganizationUser user = ES.Services.Organizations.GetUserGeneralSettings(PanelRequest.ItemID, PanelRequest.AccountID); CrmUserResult userResult = ES.Services.CRM.GetCrmUser(PanelRequest.ItemID, PanelRequest.AccountID); if (userResult.IsSuccess) { btnActive.Visible = userResult.Value.IsDisabled; locEnabled.Visible = !userResult.Value.IsDisabled; btnDeactivate.Visible = !userResult.Value.IsDisabled; locDisabled.Visible = userResult.Value.IsDisabled; lblDisplayName.Text = user.DisplayName; lblEmailAddress.Text = user.PrimaryEmailAddress; lblDomainName.Text = user.DomainUserName; int cALType = userResult.Value.CALType + ((int)userResult.Value.ClientAccessMode) * 10; Utils.SelectListItem(ddlLicenseType, cALType); } else { messageBox.ShowMessage(userResult, "GET_CRM_USER", "HostedCRM"); return; } CrmRolesResult res = ES.Services.CRM.GetCrmRoles(PanelRequest.ItemID, PanelRequest.AccountID, PanelSecurity.PackageId); if (res.IsSuccess) { gvRoles.DataSource = res.Value; gvRoles.DataBind(); } else { messageBox.ShowMessage(res, "GET_CRM_USER_ROLES", "HostedCRM"); } } catch (Exception ex) { messageBox.ShowErrorMessage("GET_CRM_USER_ROLES", ex); } } }
public static CrmRolesResult GetCRMRoles(int itemId, int accountId, int packageId) { CrmRolesResult res = StartTask <CrmRolesResult>("CRM", "GET_CRM_ROLES"); try { int serviceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.HostedCRM); if (serviceId == 0) { CompleteTask(res, CrmErrorCodes.CRM_IS_NOT_SELECTED_IN_HOSTING_PLAN, null, "CRM is not selected in hosting plan."); return(res); } CRM crm = new CRM(); ServiceProviderProxy.Init(crm, serviceId); Organization org = OrganizationController.GetOrganization(itemId); CrmUserResult crmUserResult = GetCrmUser(itemId, accountId); res.ErrorCodes.AddRange(crmUserResult.ErrorCodes); if (!crmUserResult.IsSuccess) { CompleteTask(res); return(res); } CrmUser crmUser = crmUserResult.Value; CrmRolesResult crmRoles = crm.GetAllCrmRoles(org.OrganizationId, crmUser.BusinessUnitId); res.ErrorCodes.AddRange(crmRoles.ErrorCodes); if (!crmRoles.IsSuccess) { CompleteTask(res); return(res); } Guid userId = crmUser.CRMUserId; CrmRolesResult crmUserRoles = crm.GetCrmUserRoles(org.OrganizationId, userId); res.ErrorCodes.AddRange(crmUserRoles.ErrorCodes); if (!crmUserRoles.IsSuccess) { CompleteTask(res); return(res); } foreach (CrmRole role in crmUserRoles.Value) { CrmRole retRole = crmRoles.Value.Find(delegate(CrmRole currentRole) { return(currentRole.RoleId == role.RoleId); }); if (retRole != null) { retRole.IsCurrentUserRole = true; } } res.Value = crmRoles.Value; } catch (Exception ex) { CompleteTask(res, CrmErrorCodes.CANNOT_GET_CRM_ROLES_GENERAL_ERROR, ex); return(res); } CompleteTask(); return(res); }