コード例 #1
0
        /// <summary>
        /// https://defra-custmstr-sanbox.api.crm4.dynamics.com/api/data/v8.2/defra_lobserviceuserlinks?fetchXml=%3Cfetch%20version=%271.0%27%20output-format=%27xml-platform%27%20mapping=%27logical%27%20distinct=%27false%27%3E%3Centity%20name=%27defra_lobserviceuserlink%27%3E%3Cattribute%20name=%27defra_lobserviceuserlinkid%27/%3E%3Cattribute%20name=%27defra_name%27/%3E%3Cattribute%20name=%27createdon%27/%3E%3Cattribute%20name=%27defra_serviceuser%27/%3E%3Cattribute%20name=%27defra_servicerole%27/%3E%3Corder%20attribute=%27defra_name%27%20descending=%27false%27/%3E%3Cfilter%20type=%27and%27%3E%3Ccondition%20attribute=%27statecode%27%20operator=%27eq%27%20value=%270%27/%3E%3C/filter%3E%3Clink-entity%20name=%27contact%27%20from=%27contactid%27%20to=%27defra_serviceuser%27%20link-type=%27inner%27%20alias=%27serviceLinkContact%27%3E%3Cattribute%20name=%27fullname%27/%3E%3Cfilter%20type=%27and%27%3E%3Ccondition%20attribute=%27defra_b2cobjectid%27%20operator=%27eq%27%20value=%277b1ad2d0-7946-11e8-8d36-851e870eee8a%27/%3E%3C/filter%3E%3C/link-entity%3E%3Clink-entity%20name=%27defra_lobserivcerole%27%20from=%27defra_lobserivceroleid%27%20to=%27defra_servicerole%27%20link-type=%27inner%27%20alias=%27serviceLinkRole%27%3E%3Cattribute%20name=%27defra_rolename%27/%3E%3Cattribute%20name=%27defra_name%27%20/%3Eattribute%20name=%27defra_lobserivceroleid%27/%3E%3Cfilter%20type=%27and%27%3E%3Ccondition%20attribute=%27defra_lobservice%27%20operator=%27eq%27%20uitype=%27defra_lobservice%27%20value=%27{534BA555-037A-E811-A95B-000D3A2BC547}%27/%3E%3C/filter%3E%3C/link-entity%3E%3Clink-entity%20name=%27account%27%20from=%27accountid%27%20to=%27defra_organisation%27%20visible=%27false%27%20link-type=%27outer%27%20alias=%27serviceLinkOrganisation%27%3E%3Cattribute%20name=%27name%27/%3E%3Cattribute%20name=%27accountid%27/%3E%3C/link-entity%3E%3C/entity%3E%3C/fetch%3E
        ///
        /// https://defra-custmstr-sanbox.api.crm4.dynamics.com/api/data/v8.2/defra_lobserviceuserlinks?fetchXml=<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='defra_lobserviceuserlink'><attribute name='defra_lobserviceuserlinkid'/><attribute name='defra_name'/><attribute name='createdon'/><attribute name='defra_serviceuser'/><attribute name='defra_servicerole'/><order attribute='defra_name' descending='false'/><filter type='and'><condition attribute='statecode' operator='eq' value='0'/></filter><link-entity name='contact' from='contactid' to='defra_serviceuser' link-type='inner' alias='serviceLinkContact'><attribute name='fullname'/><filter type='and'><condition attribute='defra_b2cobjectid' operator='eq' value='7b1ad2d0-7946-11e8-8d36-851e870eee8a'/></filter></link-entity><link-entity name='defra_lobserivcerole' from='defra_lobserivceroleid' to='defra_servicerole' link-type='inner' alias='serviceLinkRole'><attribute name='defra_rolename'/><attribute name='defra_name' />attribute name='defra_lobserivceroleid'/><filter type='and'><condition attribute='defra_lobservice' operator='eq' uitype='defra_lobservice' value='{534BA555-037A-E811-A95B-000D3A2BC547}'/></filter></link-entity><link-entity name='account' from='accountid' to='defra_organisation' visible='false' link-type='outer' alias='serviceLinkOrganisation'><attribute name='name'/><attribute name='accountid'/></link-entity></entity></fetch>
        /// </summary>
        /// <param name="ServiceID">{534BA555-037A-E811-A95B-000D3A2BC547}</param>
        /// <param name="b2cObjectId">7b1ad2d0-7946-11e8-8d36-851e870eee8a</param>
        /// <returns></returns>
        public ServiceUserLinks Authz(string serviceID, string b2cObjectId)
        {
            string fetchXmlRequest = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='defra_lobserviceuserlink'>" +
                                     "<attribute name='defra_lobserviceuserlinkid'/><attribute name='defra_name'/> <attribute name = 'defra_enrolmentstatus' /> " +
                                     "<attribute name='createdon'/><attribute name='defra_serviceuser'/><attribute name='defra_servicerole'/>" +
                                     "<order attribute='defra_name' descending='false'/><filter type='and'><condition attribute='statecode' operator='eq' value='0'/></filter>" +
                                     "<link-entity name='contact' from='contactid' to='defra_serviceuser' link-type='inner' alias='serviceLinkContact'>" +
                                     "<attribute name='fullname'/><filter type='and'><condition attribute='defra_b2cobjectid' operator='eq' value='" + b2cObjectId + "'/></filter>" +
                                     "</link-entity><link-entity name='defra_lobserivcerole' from='defra_lobserivceroleid' to='defra_servicerole' link-type='inner' alias='serviceLinkRole'>" +
                                     "<attribute name='defra_name'/><attribute name='defra_name'/><attribute name='defra_lobserivceroleid'/><filter type='and'>" +
                                     "<condition attribute='defra_lobservice' operator='eq' uitype='defra_lobservice' value='{" + serviceID + "}'/>" +
                                     "</filter></link-entity><link-entity name='account' from='accountid' to='defra_organisation' visible='false' link-type='outer' alias='serviceLinkOrganisation'>" +
                                     "<attribute name='name'/><attribute name='accountid'/></link-entity></entity></fetch>";

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, httpClient.BaseAddress + "defra_lobserviceuserlinks?fetchXml=" + fetchXmlRequest);



            //HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, _resource + "api/data/v8.2/defra_InitialMatch");
            //request.Content = new StringContent(paramsContent);
            //request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            var content = httpClient.SendAsync(request).Result;

            if (!content.IsSuccessStatusCode)
            {
                throw new WebFaultException(content.ReasonPhrase, (int)content.StatusCode);
            }


            ServiceUserLinks contentResponse = JsonConvert.DeserializeObject <ServiceUserLinks>(content.Content.ReadAsStringAsync().Result);

            return(contentResponse);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ServiceID"></param>
        /// <param name="UPN"></param>
        /// <returns></returns>
        public ServiceUserLinks Authz(string ServiceID, string UPN)
        {
            string fetchXmlRequest = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='defra_lobserviceuserlink'>" +
                                     "<attribute name='defra_lobserviceuserlinkid'/><attribute name='defra_name'/>" +
                                     "<attribute name='createdon'/><attribute name='defra_serviceuser'/><attribute name='defra_servicerole'/>" +
                                     "<order attribute='defra_name' descending='false'/><filter type='and'><condition attribute='statecode' operator='eq' value='0'/></filter>" +
                                     "<link-entity name='contact' from='contactid' to='defra_serviceuser' link-type='inner' alias='serviceLinkContact'>" +
                                     "<attribute name='fullname'/><filter type='and'><condition attribute='defra_upn' operator='eq' value='" + UPN + "'/></filter>" +
                                     "</link-entity><link-entity name='defra_lobserivcerole' from='defra_lobserivceroleid' to='defra_servicerole' link-type='inner' alias='serviceLinkRole'>" +
                                     "<attribute name='defra_rolename'/><attribute name='defra_name'/><attribute name='defra_lobserivceroleid'/><filter type='and'>" +
                                     "<condition attribute='defra_lobservice' operator='eq' uitype='defra_lobservice' value='{" + ServiceID + "}'/>" +
                                     "</filter></link-entity><link-entity name='account' from='accountid' to='defra_organisation' visible='false' link-type='outer' alias='serviceLinkOrganisation'>" +
                                     "<attribute name='name'/><attribute name='accountid'/></link-entity></entity></fetch>";

            HttpRequestMessage  request         = new HttpRequestMessage(HttpMethod.Get, _resource + "api/data/v8.2/defra_lobserviceuserlinks?fetchXml=" + fetchXmlRequest);
            HttpResponseMessage responseContent = ConnectToCRM(request);
            var content = responseContent.Content.ReadAsStringAsync().Result;
            ServiceUserLinks contentResponse = JsonConvert.DeserializeObject <ServiceUserLinks>(content);

            return(contentResponse);
        }
コード例 #3
0
        public AuthzResponse Authz([FromQuery] string serviceid, [FromQuery] string b2cobjectid)
        {
            List <string> rolesList    = new List <string>();
            List <string> mappingsList = new List <string>();

            try
            {
                if (!string.IsNullOrEmpty(b2cobjectid))
                {
                    if (!string.IsNullOrEmpty(serviceid))
                    {
                        ServiceUserLinks serviceUserLinks = _crmApiWrapper.Authz(serviceid, b2cobjectid);

                        foreach (ServiceUserLink serviceUserLink in serviceUserLinks.serviceUserLinks)
                        {
                            string roleListItem = serviceUserLink.OrganisationId + ":" + serviceUserLink.RoleId + ":" + serviceUserLink.EnrolmentStatus;
                            if (!rolesList.Contains(roleListItem))
                            {
                                rolesList.Add(roleListItem);
                            }

                            string mappingListOrgItem = serviceUserLink.OrganisationId + ":" + serviceUserLink.OrganisationName;
                            if (!mappingsList.Contains(mappingListOrgItem))
                            {
                                mappingsList.Add(mappingListOrgItem);
                            }

                            string mappingListRoleItem = serviceUserLink.RoleId + ":" + serviceUserLink.RoleName;
                            if (!mappingsList.Contains(mappingListRoleItem))
                            {
                                mappingsList.Add(mappingListRoleItem);
                            }

                            string mappingListStatus = serviceUserLink.EnrolmentStatus + ":" + serviceUserLink.EnrolmentStatusText;
                            if (!mappingsList.Contains(mappingListStatus))
                            {
                                mappingsList.Add(mappingListStatus);
                            }

                            // mappingsList.Add(mappingListStatus);
                        }

                        if (serviceUserLinks == null || serviceUserLinks.serviceUserLinks == null || serviceUserLinks.serviceUserLinks.Count == 0)
                        {
                            return(new AuthzResponse
                            {
                                status = 204,
                                message = "No Content",
                                version = "1.0.0.0",
                                roles = rolesList,
                                mappings = mappingsList
                            });
                        }
                    }
                    else
                    {
                        return(new AuthzResponse
                        {
                            status = 400,
                            message = "ServiceId is invalid",
                            version = "1.0.0.0",
                            roles = rolesList,
                            mappings = mappingsList
                        });
                    }
                }
                else
                {
                    return(new AuthzResponse
                    {
                        status = 400,
                        message = "B2CObjectId is invalid",
                        version = "1.0.0.0",
                        roles = rolesList,
                        mappings = mappingsList
                    });
                }
            }
            catch (WebFaultException ex)
            {
                System.Diagnostics.Trace.TraceError(ex.Message);
                return(new AuthzResponse
                {
                    status = 400,
                    message = ex.ErrorMsg,
                    version = "1.0.0.0",
                    roles = rolesList,
                    mappings = mappingsList
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError(ex.Message);
                return(new AuthzResponse
                {
                    status = 500,
                    message = ex.Message,
                    version = "1.0.0.0",
                    roles = rolesList,
                    mappings = mappingsList
                });
            }

            return(new AuthzResponse
            {
                status = 200,
                message = "Success!",
                version = "1.0.0.0",
                roles = rolesList,
                mappings = mappingsList
            });
        }