public static List <CRMProductCatalogModel> CRMGetEntireProductCatalogService() { List <CRMProductCatalogModel> theProducts = new List <CRMProductCatalogModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_productcatalog", ColumnSet = new ColumnSet("csi_gtin", "csi_gtinbox", "csi_modelnbr", "csi_partnbr", "csi_sellingdescription") }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMProductCatalogModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMProductCatalogModel(); if (entityRecords[i].Contains("csi_gtin") && entityRecords[i]["csi_gtin"] != null) { entityModel.CSI_GTIN = entityRecords[i]["csi_gtin"].ToString(); } if (entityRecords[i].Contains("csi_gtinbox") && entityRecords[i]["csi_gtinbox"] != null) { entityModel.CSI_GTINBox = entityRecords[i]["csi_gtinbox"].ToString(); } if (entityRecords[i].Contains("csi_modelnbr") && entityRecords[i]["csi_modelnbr"] != null) { entityModel.CSI_ModelNbr = entityRecords[i]["csi_modelnbr"].ToString(); } if (entityRecords[i].Contains("csi_partnbr") && entityRecords[i]["csi_partnbr"] != null) { entityModel.CSI_PartNbr = entityRecords[i]["csi_partnbr"].ToString(); } if (entityRecords[i].Contains("csi_sellingdescription") && entityRecords[i]["csi_sellingdescription"] != null) { entityModel.CSI_SellingDescription = entityRecords[i]["csi_sellingdescription"].ToString(); } // add row to collection theProducts.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theProducts); }
public static bool CRMIsTeamActiveService(string teamID) { bool teamActive = true; try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "team", ColumnSet = new ColumnSet("teamid", "csi_activeterritory"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("teamid", ConditionOperator.Equal, teamID.Trim()) } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { for (int i = 0; i < entityRecords.Entities.Count; i++) { if (entityRecords[i].Contains("csi_activeterritory") && entityRecords[i]["csi_activeterritory"] != null) { string terrActive = entityRecords[i].GetAttributeValue <OptionSetValue>("csi_activeterritory").Value.ToString(); if (terrActive != "862530000") { // not an active team with this value teamActive = false; } } } } } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } return(teamActive); }
/// <summary> /// Get the Growth Driver Name for the passed in ID /// </summary> /// <param name="growthDriverID">Growth Driver ID (not primary key GUID)</param> /// <returns>String of name</returns> public static string CRMGetGrowthDriverNameService(int growthDriverID) { string gdName = String.Empty; try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_growthdriver", ColumnSet = new ColumnSet("csi_goalgrowthdriverid", "csi_growthdrivername"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.Or, Conditions = { new ConditionExpression("csi_goalgrowthdriverid", ConditionOperator.Equal, growthDriverID) } } } } }; // return records sorted query.AddOrder("csi_sortorder", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { for (int i = 0; i < entityRecords.Entities.Count; i++) { if (entityRecords[i].Contains("csi_growthdrivername") && entityRecords[i]["csi_growthdrivername"] != null) { gdName = entityRecords[i]["csi_growthdrivername"].ToString(); break; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(gdName); }
public static string GetCRMTeamNameService(string teamID) { string teamName = string.Empty; try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "team", ColumnSet = new ColumnSet("teamid", "name"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("teamid", ConditionOperator.Equal, teamID.Trim()), new ConditionExpression("csi_activeterritory", ConditionOperator.Equal, "862530000") } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { for (int i = 0; i < entityRecords.Entities.Count; i++) { if (entityRecords[i].Contains("name") && entityRecords[i]["name"] != null) { teamName = entityRecords[i]["name"].ToString(); } } } } catch (System.Exception ex) { System.Console.WriteLine(ex.Message); } return(teamName); }
public static string CRMGetStatusNameService(int statusID) { string statusName = String.Empty; try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_goalstatus", ColumnSet = new ColumnSet("csi_statusid", "csi_statusname"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("csi_statusid", ConditionOperator.Equal, statusID) } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { for (int i = 0; i < entityRecords.Entities.Count; i++) { if (entityRecords[i].Contains("csi_statusname") && entityRecords[i]["csi_statusname"] != null) { statusName = entityRecords[i]["csi_statusname"].ToString(); break; } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(statusName); }
public static List <CRMStateModel> CRMGetStateListService() { List <CRMStateModel> theStates = new List <CRMStateModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "new_state", ColumnSet = new ColumnSet("new_stateid", "new_statename") }; // return records sorted by name //query.AddOrder("csi_facilityname", OrderType.Ascending); query.AddOrder("new_statename", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMStateModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMStateModel(); if (entityRecords[i].Contains("new_stateid") && entityRecords[i]["new_stateid"] != null) { entityModel.StateID = entityRecords[i]["new_stateid"].ToString(); } if (entityRecords[i].Contains("new_statename") && entityRecords[i]["new_statename"] != null) { entityModel.StateName = entityRecords[i]["new_statename"].ToString(); } // add row to collection theStates.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theStates); }
public static List <CRMGrowthDriverModel> CRMGetGrowthDriverListService() { List <CRMGrowthDriverModel> theDrivers = new List <CRMGrowthDriverModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_growthdriver", ColumnSet = new ColumnSet("csi_goalgrowthdriverid", "csi_growthdrivername") }; // return records sorted query.AddOrder("csi_sortorder", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMGrowthDriverModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMGrowthDriverModel(); if (entityRecords[i].Contains("csi_goalgrowthdriverid") && entityRecords[i]["csi_goalgrowthdriverid"] != null) { entityModel.CSI_GoalGrowthDriverID = Convert.ToInt32(entityRecords[i]["csi_goalgrowthdriverid"]); } if (entityRecords[i].Contains("csi_growthdrivername") && entityRecords[i]["csi_growthdrivername"] != null) { entityModel.CSI_GrowthDriverName = entityRecords[i]["csi_growthdrivername"].ToString(); } // add row to collection theDrivers.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theDrivers); }
/// <summary> /// Get the Timeline values /// </summary> /// <returns>List of Timeline values</returns> public static List <CRMGoalTimelineModel> GetCRMGetGoalTimelineListService() { List <CRMGoalTimelineModel> theTimeline = new List <CRMGoalTimelineModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_goaltimeline", ColumnSet = new ColumnSet("csi_timelineid", "csi_timelinename") }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMGoalTimelineModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMGoalTimelineModel(); if (entityRecords[i].Contains("csi_timelineid") && entityRecords[i]["csi_timelineid"] != null) { entityModel.CSI_TimelineID = Convert.ToInt32(entityRecords[i]["csi_timelineid"]); } if (entityRecords[i].Contains("csi_timelinename") && entityRecords[i]["csi_timelinename"] != null) { entityModel.CSI_TimelineName = entityRecords[i]["csi_timelinename"].ToString(); } // add row to collection theTimeline.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theTimeline); }
/// <summary> /// Queries the Goals Entity /// Returning the highest integer value from /// the Goal Identifier field /// Used to give user easy way to reference a goal /// Represents a seqntial number /// But not used for any other purpose /// </summary> /// <returns>Maximum value in the Goals Entity for Goal Identifier field</returns> public static int CRMGetMaxGoalIDService() { int maxVal = 0; try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_goals", ColumnSet = new ColumnSet("csi_goalidentifier"), }; // return records sorted query.AddOrder("csi_goalidentifier", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { // only interest in last value in that records are sorted in ascending order int lastRecord = entityRecords.Entities.Count - 1; if (entityRecords[lastRecord].Contains("csi_goalidentifier") && entityRecords[lastRecord]["csi_goalidentifier"] != null) { // last value--highest number maxVal = Convert.ToInt32(entityRecords[lastRecord]["csi_goalidentifier"]); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(maxVal); }
public static List <CRMAccountModel> CRMGetSharedAccountsService(string userID) { List <CRMAccountModel> theAccts = new List <CRMAccountModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; Guid objGuid = Guid.Empty; if (Guid.TryParse(userID, out objGuid)) { // string can be converted to GUID // no additional processing needed } else { // can not parse into a guid throw new Exception("Can not convert User ID into GUID"); } QueryExpression query = new QueryExpression { EntityName = "principalobjectaccess", ColumnSet = new ColumnSet("objectid"), LinkEntities = { new LinkEntity { Columns = new ColumnSet("accountid", "name"), EntityAlias = "acct", JoinOperator = JoinOperator.LeftOuter, LinkFromAttributeName = "objectid", LinkFromEntityName = "principalobjectaccess", LinkToAttributeName = "accountid", LinkToEntityName = "account" } }, Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("objecttypecode", ConditionOperator.Equal, "account"), new ConditionExpression("principaltypecode", ConditionOperator.Equal, "systemuser"), new ConditionExpression("principalid", ConditionOperator.Equal, objGuid) } } } } }; // return records sorted by name //query.AddOrder("csi_facilityname", OrderType.Ascending); //query.AddOrder("name", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMAccountModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMAccountModel(); if (entityRecords[i].Contains("acct.accountid") && entityRecords[i]["acct.accountid"] != null) { AliasedValue acctID = entityRecords[i].GetAttributeValue <AliasedValue>("acct.accountid"); entityModel.Id = acctID.Value.ToString(); } if (entityRecords[i].Contains("acct.name") && entityRecords[i]["acct.name"] != null) { AliasedValue acctN = entityRecords[i].GetAttributeValue <AliasedValue>("acct.name"); entityModel.Name = CRMUtilityServices.GetTitleCaseService(acctN.Value.ToString()); entityModel.CSI_FacilityName = entityModel.Name; } // add row to collection theAccts.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theAccts); }
public static List <CRMScanHeaderModel> CRMGetMyScansService(string UserID, string TeamID) { List <CRMScanHeaderModel> myScans = new List <CRMScanHeaderModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; Guid TeamGuid = Guid.Empty; if (Guid.TryParse(TeamID, out TeamGuid)) { // string can be converted to GUID // no additional processing needed } else { // can not parse into a guid throw new Exception("Can not convert TeamID into GUID"); } Guid UserGuid = Guid.Empty; if (Guid.TryParse(UserID, out UserGuid)) { // string can be converted to GUID // no additional processing needed } else { // can not parse into a guid throw new Exception("Can not convert UserID into GUID"); } QueryExpression query = new QueryExpression { EntityName = "po_inventoryscan", ColumnSet = new ColumnSet("po_name", "createdby", "createdon", "po_account", "ownerid", "po_scantype"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.Or, Conditions = { new ConditionExpression("ownerid", ConditionOperator.Equal, UserGuid), new ConditionExpression("po_territoryteam", ConditionOperator.Equal, TeamGuid) } } } } }; // return records sorted by name //query.AddOrder("csi_facilityname", OrderType.Ascending); //query.AddOrder("name", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMScanHeaderModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMScanHeaderModel(); if (entityRecords[i].Contains("po_name") && entityRecords[i]["po_name"] != null) { entityModel.ScanName = entityRecords[i]["po_name"].ToString(); } if (entityRecords[i].Contains("createdon") && entityRecords[i]["createdon"] != null) { entityModel.CreatedDate = Convert.ToDateTime(entityRecords[i]["createdon"]); entityModel.CreatedDateString = entityModel.CreatedDate.ToString("yyyy/MM/dd"); } if (entityRecords[i].Contains("po_inventoryscanid") && entityRecords[i]["po_inventoryscanid"] != null) { entityModel.ScanID = entityRecords[i]["po_inventoryscanid"].ToString(); } if (entityRecords[i].Contains("po_scantype") && entityRecords[i]["po_scantype"] != null) { entityModel.ScanTypeName = entityRecords[i].FormattedValues["po_scantype"].ToString(); } if (entityRecords[i].Contains("ownerid") && entityRecords[i]["ownerid"] != null) { //EntityReference ownerRef = entityRecords[i].GetAttributeValue<EntityReference>("ownerid"); //entityModel.OwnerID = ownerRef.Id.ToString(); //entityModel.OwnerID = entityRecords[i]["ownerid"].ToString(); } if (entityRecords[i].Contains("po_account") && entityRecords[i]["po_account"] != null) { EntityReference accountRef = entityRecords[i].GetAttributeValue <EntityReference>("po_account"); entityModel.AccountID = accountRef.Id.ToString(); entityModel.AccountName = accountRef.Name.ToString(); //entityModel = entityRecords[i]["new_dsm2"].ToString(); } else { entityModel.AccountID = ""; entityModel.AccountName = ""; } entityModel.ScanStatus = i % 4; // add row to collection myScans.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(myScans); }
/// <summary> /// Returns information about the user /// When given a UserID (i.e. login ID) /// </summary> /// <param name="userID">User ID</param> /// <returns>CRM User Model</returns> public static List <CRMSystemUserModel> GetCRMSystemUserService(string userID) { List <CRMSystemUserModel> theUser = new List <CRMSystemUserModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "systemuser", ColumnSet = new ColumnSet("systemuserid", "islicensed", "isdisabled", "internalemailaddress", "yomifullname", "title", "lastname", "firstname", "employeeid", "domainname", "fullname"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("islicensed", ConditionOperator.Equal, true), new ConditionExpression("internalemailaddress", ConditionOperator.BeginsWith, userID.Trim()) } } } } }; EntityCollection systemUserRecords = _orgService.RetrieveMultiple(query); // see if data returned if (systemUserRecords != null && systemUserRecords.Entities.Count > 0) { CRMSystemUserModel sysUserModel; for (int i = 0; i < systemUserRecords.Entities.Count; i++) { // new blank copy of the C# model sysUserModel = new CRMSystemUserModel(); if (systemUserRecords[i].Contains("systemuserid") && systemUserRecords[i]["systemuserid"] != null) { sysUserModel.SystemUserId = systemUserRecords[i]["systemuserid"].ToString(); } if (systemUserRecords[i].Contains("islicensed") && systemUserRecords[i]["islicensed"] != null) { sysUserModel.IsLicensed = Convert.ToBoolean(systemUserRecords[i]["islicensed"]); } if (systemUserRecords[i].Contains("isdisabled") && systemUserRecords[i]["isdisabled"] != null) { sysUserModel.IsDisabled = Convert.ToBoolean(systemUserRecords[i]["isdisabled"]); } if (systemUserRecords[i].Contains("internalemailaddress") && systemUserRecords[i]["internalemailaddress"] != null) { sysUserModel.InternalEmailAddress = systemUserRecords[i]["internalemailaddress"].ToString(); } if (systemUserRecords[i].Contains("yomifullname") && systemUserRecords[i]["yomifullname"] != null) { sysUserModel.YomiFullName = systemUserRecords[i]["yomifullname"].ToString(); } if (systemUserRecords[i].Contains("title") && systemUserRecords[i]["title"] != null) { sysUserModel.Title = systemUserRecords[i]["title"].ToString(); } if (systemUserRecords[i].Contains("lastname") && systemUserRecords[i]["lastname"] != null) { sysUserModel.LastName = systemUserRecords[i]["lastname"].ToString(); } if (systemUserRecords[i].Contains("firstname") && systemUserRecords[i]["firstname"] != null) { sysUserModel.FirstName = systemUserRecords[i]["firstname"].ToString(); } if (systemUserRecords[i].Contains("employeeid") && systemUserRecords[i]["employeeid"] != null) { sysUserModel.EmployeeId = systemUserRecords[i]["employeeid"].ToString(); } if (systemUserRecords[i].Contains("domainname") && systemUserRecords[i]["domainname"] != null) { sysUserModel.DomainName = systemUserRecords[i]["domainname"].ToString(); } if (systemUserRecords[i].Contains("fullname") && systemUserRecords[i]["fullname"] != null) { sysUserModel.FullName = systemUserRecords[i]["fullname"].ToString(); } // add row to collection theUser.Add(sysUserModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theUser); }
public static List <CRMNewRelationshipModel> GetCRMRelationshipsForAccountServices(string accountID) { List <CRMNewRelationshipModel> theRelationships = new List <CRMNewRelationshipModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "new_relationship", ColumnSet = new ColumnSet("new_contact", "new_account"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("new_account", ConditionOperator.Equal, accountID.Trim()), new ConditionExpression("statuscode", ConditionOperator.Equal, 1) } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMNewRelationshipModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMNewRelationshipModel(); if (entityRecords[i].Contains("new_contact") && entityRecords[i]["new_contact"] != null) { EntityReference contractRef = entityRecords[i].GetAttributeValue <EntityReference>("new_contact"); entityModel.New_Contact = contractRef.Id.ToString(); } if (entityRecords[i].Contains("new_account") && entityRecords[i]["new_account"] != null) { EntityReference acctRef = entityRecords[i].GetAttributeValue <EntityReference>("new_account"); entityModel.New_Account = acctRef.Id.ToString(); } // add row to collection theRelationships.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theRelationships); }
public static List <CRMSalesHierarchyModel> CRMGetSalesHierarchyForRSMService(string mgrID) { List <CRMSalesHierarchyModel> theHier = new List <CRMSalesHierarchyModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; mgrID = mgrID.ToLower(); QueryExpression query = new QueryExpression { EntityName = "team", ColumnSet = new ColumnSet("name", "new_territory", "teamid"), LinkEntities = { new LinkEntity { Columns = new ColumnSet("name", "csi_rsmuserid", "csi_asduserid"), EntityAlias = "region", JoinOperator = JoinOperator.LeftOuter, LinkFromAttributeName = "new_territory", LinkFromEntityName = "team", LinkToAttributeName = "teamid", LinkToEntityName = "team" } }, Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("csi_activeterritory", ConditionOperator.Equal, 862530000) } } } } }; // return records sorted by name //query.AddOrder("csi_facilityname", OrderType.Ascending); query.AddOrder("name", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); bool addTeam = false; // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMSalesHierarchyModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMSalesHierarchyModel(); addTeam = false; if (entityRecords[i].Contains("name") && entityRecords[i]["name"] != null) { entityModel.SalesTeamName = entityRecords[i]["name"].ToString(); } if (entityRecords[i].Contains("teamid") && entityRecords[i]["teamid"] != null) { entityModel.SalesTeamID = entityRecords[i]["teamid"].ToString(); } if (entityRecords[i].Contains("new_territory") && entityRecords[i]["new_territory"] != null) { EntityReference regionRef = entityRecords[i].GetAttributeValue <EntityReference>("new_territory"); entityModel.RegionID = regionRef.Id.ToString(); } if (entityRecords[i].Contains("region.name") && entityRecords[i]["region.name"] != null) { AliasedValue rName = entityRecords[i].GetAttributeValue <AliasedValue>("region.name"); entityModel.RegionName = rName.Value.ToString(); } if (entityRecords[i].Contains("region.csi_rsmuserid") && entityRecords[i]["region.csi_rsmuserid"] != null) { AliasedValue rmsID = entityRecords[i].GetAttributeValue <AliasedValue>("region.csi_rsmuserid"); EntityReference rid = (EntityReference)rmsID.Value; entityModel.RSMID = rid.Id.ToString(); // check for match if (entityModel.RSMID.ToLower() == mgrID) { // match found--set flag addTeam = true; } } if (entityRecords[i].Contains("region.csi_asduserid") && entityRecords[i]["region.csi_asduserid"] != null) { AliasedValue avpID = entityRecords[i].GetAttributeValue <AliasedValue>("region.csi_asduserid"); EntityReference aid = (EntityReference)avpID.Value; entityModel.AVPID = aid.Id.ToString(); } // add row to collection if (addTeam == true) { // only add if match theHier.Add(entityModel); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theHier); }
public static List <CRMTeamMembershipModel> GetCRMTeamMembershipsService(string systemUserID) { List <CRMTeamMembershipModel> myTeams = new List <CRMTeamMembershipModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "teammembership", ColumnSet = new ColumnSet("systemuserid", "teamid", "teammembershipid"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("systemuserid", ConditionOperator.Equal, systemUserID.Trim()) } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMTeamMembershipModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMTeamMembershipModel(); // check for active teams--if record is not active--do not continue to add if (CRMTeamsServices.CRMIsTeamActiveService(entityRecords[i]["teamid"].ToString())) { if (entityRecords[i].Contains("systemuserid") && entityRecords[i]["systemuserid"] != null) { entityModel.SystemUserId = entityRecords[i]["systemuserid"].ToString(); } if (entityRecords[i].Contains("teamid") && entityRecords[i]["teamid"] != null) { entityModel.TeamId = entityRecords[i]["teamid"].ToString(); entityModel.TeamName = CRMTeamsServices.GetCRMTeamNameService(entityModel.TeamId); } if (entityRecords[i].Contains("teammembershipid") && entityRecords[i]["teammembershipid"] != null) { entityModel.TeamMembershipId = entityRecords[i]["teammembershipid"].ToString(); } // add row to collection myTeams.Add(entityModel); } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(myTeams); }
public static int CRMSaveNewContactService(CRMContactModel theCnt) { int rc = 0; try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; Entity contact = new Entity("contact"); contact["fullname"] = theCnt.ContactName; contact["firstname"] = theCnt.FirstName; contact["lastname"] = theCnt.LastName; contact["new_specialty"] = new OptionSetValue(Convert.ToInt32(theCnt.SpecialtyID)); contact["new_npi"] = theCnt.NPI; contact["emailaddress1"] = theCnt.EMAIL; Guid objGuid = Guid.Empty; if (Guid.TryParse(theCnt.StateID, out objGuid)) { // string can be converted to GUID contact["new_state"] = new EntityReference("new_state", objGuid); } else { // can not parse state into a guid rc = 100; // bad state guid } // try to convert Account ID as a string into GUID Guid acctGuid = Guid.Empty; if (Guid.TryParse(theCnt.AccountID, out acctGuid)) { // success--not immediate action needed } else { // can not parse rc = 200; // bad Account ID } // only execute if no conversion errors if (rc == 0) { // create the contact record // returns ID of new record Guid contactID = _orgService.Create(contact); // Next create the relationship record with the Account entity Entity relationship = new Entity("new_relationship"); relationship["new_contact"] = new EntityReference("contact", contactID); relationship["statuscode"] = 1; relationship["new_account"] = new EntityReference("account", acctGuid); relationship["new_firstname"] = theCnt.FirstName; relationship["new_lastname"] = theCnt.LastName; relationship["new_name"] = theCnt.ContactName; Guid relationshipID = _orgService.Create(relationship); } } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ex) { Console.WriteLine(ex.Message); rc = 300; // try-catch exception } return(rc); }
public static List <CRMContactModel> GetCRMContactsForRelationshipService(string relationshipID) { List <CRMContactModel> theContacts = new List <CRMContactModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "contact", ColumnSet = new ColumnSet("contactid", "fullname"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.And, Conditions = { new ConditionExpression("contactid", ConditionOperator.Equal, relationshipID.Trim()) } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMContactModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMContactModel(); if (entityRecords[i].Contains("contactid") && entityRecords[i]["contactid"] != null) { entityModel.Id = entityRecords[i]["contactid"].ToString(); } if (entityRecords[i].Contains("fullname") && entityRecords[i]["fullname"] != null) { entityModel.ContactName = CRMUtilityServices.GetTitleCaseService(entityRecords[i]["fullname"].ToString()); } // add row to collection theContacts.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theContacts); }
/// <summary> /// Get the Goal Categories for a given Growth Driver /// From CRM Entities /// </summary> /// <param name="growthDriver">Growth Driver to filter on</param> /// <returns>List of Goal Categories</returns> public static List <CRMGoalCategoriesModel> CRMGetGoalCategoriesForGrowthDriverService(int growthDriver) { List <CRMGoalCategoriesModel> theCats = new List <CRMGoalCategoriesModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; QueryExpression query = new QueryExpression { EntityName = "csi_goalcategories", ColumnSet = new ColumnSet("csi_categoryid", "csi_goalcategoryname"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.Or, Conditions = { new ConditionExpression("csi_goalgrowthdriverid", ConditionOperator.Equal, growthDriver) } } } } }; EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMGoalCategoriesModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMGoalCategoriesModel(); if (entityRecords[i].Contains("csi_categoryid") && entityRecords[i]["csi_categoryid"] != null) { entityModel.CSI_CategoryID = Convert.ToInt32(entityRecords[i]["csi_categoryid"]); } if (entityRecords[i].Contains("csi_goalcategoryname") && entityRecords[i]["csi_goalcategoryname"] != null) { entityModel.CSI_GoalCategoryName = entityRecords[i]["csi_goalcategoryname"].ToString(); } // add row to collection theCats.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theCats); }
/// <summary> /// Gets the Accounts associated with a Team and/or DSM2 /// </summary> /// <param name="TeamID">Team or DSM2 ID</param> /// <param name="DSM2">Not Used</param> /// <returns>List of Account Model class</returns> public static List <CRMAccountModel> GetCRMAccountsForTeamService(string TeamID, string DSM2) { List <CRMAccountModel> theAccounts = new List <CRMAccountModel>(); try { CrmServiceClient conn = new CrmServiceClient(DatabaseServices.GetCRMDBConnectionString()); IOrganizationService _orgService; _orgService = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy; Guid objGuid = Guid.Empty; if (Guid.TryParse(TeamID, out objGuid)) { // string can be converted to GUID // no additional processing needed } else { // can not parse into a guid throw new Exception("Can not convert TeamID into GUID"); } QueryExpression query = new QueryExpression { EntityName = "account", ColumnSet = new ColumnSet("accountid", "name", "csi_facilityname", "ownerid", "new_dsm2"), Criteria = { Filters = { new FilterExpression { FilterOperator = LogicalOperator.Or, Conditions = { //new ConditionExpression("ownerid", ConditionOperator.Equal, TeamID.Trim()), new ConditionExpression("ownerid", ConditionOperator.Equal, objGuid), //new ConditionExpression("new_dsm2", ConditionOperator.Equal, TeamID.Trim()) new ConditionExpression("new_dsm2", ConditionOperator.Equal, objGuid) } } } } }; // return records sorted by name //query.AddOrder("csi_facilityname", OrderType.Ascending); query.AddOrder("name", OrderType.Ascending); EntityCollection entityRecords = _orgService.RetrieveMultiple(query); // see if data returned if (entityRecords != null && entityRecords.Entities.Count > 0) { CRMAccountModel entityModel; for (int i = 0; i < entityRecords.Entities.Count; i++) { // new blank copy of the C# model entityModel = new CRMAccountModel(); if (entityRecords[i].Contains("accountid") && entityRecords[i]["accountid"] != null) { entityModel.Id = entityRecords[i]["accountid"].ToString(); } if (entityRecords[i].Contains("csi_facilityname") && entityRecords[i]["csi_facilityname"] != null) { entityModel.CSI_FacilityName = entityRecords[i]["csi_facilityname"].ToString(); } if (entityRecords[i].Contains("name") && entityRecords[i]["name"] != null) { entityModel.Name = CRMUtilityServices.GetTitleCaseService(entityRecords[i]["name"].ToString()); } if (entityRecords[i].Contains("ownerid") && entityRecords[i]["ownerid"] != null) { EntityReference ownerRef = entityRecords[i].GetAttributeValue <EntityReference>("ownerid"); entityModel.OwnerID = ownerRef.Id.ToString(); //entityModel.OwnerID = entityRecords[i]["ownerid"].ToString(); } if (entityRecords[i].Contains("new_dsm2") && entityRecords[i]["new_dsm2"] != null) { EntityReference ownerRef = entityRecords[i].GetAttributeValue <EntityReference>("new_dsm2"); entityModel.OwnerID = ownerRef.Id.ToString(); //entityModel.New_DSM2 = entityRecords[i]["new_dsm2"].ToString(); } // add row to collection theAccounts.Add(entityModel); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(theAccounts); }