Example #1
0
        public async Task <List <Entity> > QualifyLeadAsync(QualifyLeadRequest action)
        {
            string  fullUrl = $"{ApiUrl}/leads({action.LeadId:P})/Microsoft.Dynamics.CRM.QualifyLead";
            JObject jObject = action.GetRequestObject();

            var request = new HttpRequestMessage(new HttpMethod("POST"), fullUrl)
            {
                Content = new StringContent(JsonConvert.SerializeObject(jObject), Encoding.UTF8, "application/json")
            };

            HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request);

            ResponseValidator.EnsureSuccessStatusCode(response);
            string responseContent = await response.Content.ReadAsStringAsync();

            var           data     = JsonConvert.DeserializeObject <JObject>(responseContent);
            List <Entity> entities = QualifyLeadResponseFormatter.GetCreatedEntities(data);

            foreach (Entity entity in entities)
            {
                EntityDefinition entityDefinition = WebApiMetadata.GetEntityDefinition(entity.LogicalName);
                string           primaryKey       = entityDefinition?.PrimaryIdAttribute;
                if (entity.Contains(primaryKey))
                {
                    entity.Id = Guid.Parse(entity.GetAttributeValue <string>(primaryKey));
                }
            }

            return(entities);
        }
        public void FormatResponseTest()
        {
            var data     = JsonConvert.DeserializeObject <JObject>(ResponseJSON);
            var entities = QualifyLeadResponseFormatter.GetCreatedEntities(data);

            Assert.Equal(2, entities.Count);
            Assert.True(entities.Any(e => e.LogicalName == "contact"));
            Assert.True(entities.Any(e => e.LogicalName == "opportunity"));
        }