示例#1
0
        /// <inheritdoc />
        public async Task UpdateAsync(long contactId, AgileCrmContactRequest agileCrmContactModel)
        {
            const string MethodName = nameof(this.UpdateAsync);

            this.logger.LogMethodStart(ClassName, MethodName);

            try
            {
                // Validate argument object
                agileCrmContactModel.ValidateModel();

                // Serialize object to JSON
                var contactEntityBase = agileCrmContactModel.ToContactEntityBase();

                contactEntityBase.Id = contactId;

                var stringContent = contactEntityBase.ToStringContent();

                // Send JSON to server
                const string Uri = "contacts/edit-properties";

                var httpResponseMessage = await this.httpClient.PutAsync(Uri, stringContent).ConfigureAwait(false);

                // Analyze server response for errors
                httpResponseMessage.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                this.logger.LogException(ClassName, MethodName, exception);
                throw;
            }

            this.logger.LogUpdated(ServiceType.Contact, contactId);
            this.logger.LogMethodEnd(ClassName, MethodName);
        }
示例#2
0
        /// <inheritdoc />
        public async Task CreateAsync(AgileCrmContactRequest agileCrmContactModel)
        {
            const string MethodName = nameof(this.CreateAsync);

            this.logger.LogMethodStart(ClassName, MethodName);

            var contactId = default(long);

            try
            {
                // Validate argument object
                agileCrmContactModel.ValidateModel();

                // Serialize object to JSON
                var contactEntityBase = agileCrmContactModel.ToContactEntityBase();

                var stringContent = contactEntityBase.ToStringContent();

                // Send JSON to server
                const string Uri = "contacts";

                var httpResponseMessage = await this.httpClient.PostAsync(Uri, stringContent).ConfigureAwait(false);

                // Analyze server response for errors
                httpResponseMessage.EnsureSuccessStatusCode();

                // Retrieve identifier for logging
                var httpContentAsString = await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);

                contactId = JsonConvert.DeserializeAnonymousType(httpContentAsString, new { id = default(long) }).id;
            }
            catch (Exception exception)
            {
                this.logger.LogException(ClassName, MethodName, exception);
                throw;
            }

            this.logger.LogCreated(ServiceType.Contact, contactId);
            this.logger.LogMethodEnd(ClassName, MethodName);
        }
示例#3
0
        public void MethodName()
        {
            // Arrange
            var agileCrmContactRequest = new AgileCrmContactRequest
            {
                LeadScore    = 100,
                StarValue    = 5,
                Title        = "Title",
                FirstName    = "FirstName",
                LastName     = "LastName",
                EmailAddress = new List <AgileCrmSubTypeRequest>
                {
                    new AgileCrmSubTypeRequest
                    {
                        SubType = AgileCrmPropertySubType.EmailPersonal,
                        Value   = "*****@*****.**"
                    }
                },
                PhoneNumber = new List <AgileCrmSubTypeRequest>
                {
                    new AgileCrmSubTypeRequest
                    {
                        SubType = AgileCrmPropertySubType.PhoneHome,
                        Value   = "00000000000"
                    }
                },
                AddressInformation = new DemographicBase
                {
                    Address = "Address",
                    City    = "City",
                    State   = "State",
                    Country = "Country",
                    ZipCode = "ZipCode",
                    SubType = AgileCrmPropertySubType.AddressHome
                },
                CompanyName = "CompanyName",
                Website     = new List <AgileCrmSubTypeRequest>
                {
                    new AgileCrmSubTypeRequest
                    {
                        SubType = AgileCrmPropertySubType.WebsiteGitHub,
                        Value   = "https://www.github.com/ShadowFoxSoftworks/"
                    }
                },
                CustomFields = new Dictionary <string, string>
                {
                    { "Key", "Value" }
                },
                Tags = new List <string>
                {
                    "Tag"
                }
            };

            var agileCrmContactResponse = agileCrmContactRequest.ToContactEntity();

            // Act
            StartStopwatch();

            var result = JsonConvert.SerializeObject(agileCrmContactResponse);

            StopStopwatch();

            // Assert
            Console.WriteLine(result);

            WriteTimeElapsed();
        }
        /// <summary>
        /// Maps a AgileCrmContactEntity onto a ContactEntityBase.
        /// </summary>
        /// <param name="agileCrmContactModel">The AgileCRM contact model.</param>
        /// <returns>
        ///   <see cref="AgileCrmContactEntity" />.
        /// </returns>
        public static AgileCrmContactEntity ToContactEntityBase(this AgileCrmContactRequest agileCrmContactModel)
        {
            var agileCrmPropertyEntities = new List <AgileCrmPropertyEntityBase>
            {
                new AgileCrmPropertyEntity
                {
                    Type  = PropertyType.System,
                    Name  = ContactPropertyName.Title,
                    Value = agileCrmContactModel.Title
                },

                new AgileCrmPropertyEntity
                {
                    Type  = PropertyType.System,
                    Name  = ContactPropertyName.FirstName,
                    Value = agileCrmContactModel.FirstName
                },

                new AgileCrmPropertyEntity
                {
                    Type  = PropertyType.System,
                    Name  = ContactPropertyName.LastName,
                    Value = agileCrmContactModel.LastName
                },

                new AgileCrmPropertyEntity
                {
                    Type  = PropertyType.System,
                    Name  = ContactPropertyName.Company,
                    Value = agileCrmContactModel.CompanyName
                }
            };

            foreach (var keyValuePair in agileCrmContactModel.Phone)
            {
                agileCrmPropertyEntities.Add(
                    new AgileCrmPropertySubTypeEntity
                {
                    Type    = PropertyType.System,
                    Name    = PropertyName.Phone,
                    Value   = keyValuePair.Value,
                    SubType = keyValuePair.Key.ToPhoneTypeValue()
                });
            }

            foreach (var keyValuePair in agileCrmContactModel.Email)
            {
                agileCrmPropertyEntities.Add(
                    new AgileCrmPropertySubTypeEntity
                {
                    Type    = PropertyType.System,
                    Name    = PropertyName.Email,
                    Value   = keyValuePair.Value,
                    SubType = keyValuePair.Key.ToEmailTypeValue()
                });
            }

            foreach (var keyValuePair in agileCrmContactModel.Website)
            {
                agileCrmPropertyEntities.Add(
                    new AgileCrmPropertySubTypeEntity
                {
                    Type    = PropertyType.System,
                    Name    = PropertyName.Website,
                    Value   = keyValuePair.Value,
                    SubType = keyValuePair.Key.ToWebsiteTypeValue()
                });
            }

            agileCrmPropertyEntities.Add(
                new AgileCrmPropertyAddressEntity
            {
                Type  = PropertyType.System,
                Name  = PropertyName.Address,
                Value = new AgileCrmAddressEntity
                {
                    Address = agileCrmContactModel.Address,
                    City    = agileCrmContactModel.City,
                    State   = agileCrmContactModel.State,
                    Country = agileCrmContactModel.Country,
                    ZipCode = agileCrmContactModel.ZipCode
                },
                SubType = agileCrmContactModel.AddressType.ToAddressTypeValue()
            });

            foreach (var keyValuePair in agileCrmContactModel.CustomFields)
            {
                agileCrmPropertyEntities.Add(
                    new AgileCrmPropertyEntity
                {
                    Type  = PropertyType.Custom,
                    Name  = keyValuePair.Key,
                    Value = keyValuePair.Value
                });
            }

            var tagsCollection = new List <string>();

            foreach (var stringItem in agileCrmContactModel.Tags)
            {
                tagsCollection.Add(stringItem);
            }

            var agileCrmServerContactEntity = new AgileCrmContactEntity
            {
                // Id = (set by calling method if required).
                // CompanyId = (set by calling method if required).
                StarValue  = agileCrmContactModel.StarValue,
                LeadScore  = agileCrmContactModel.LeadScore,
                Properties = agileCrmPropertyEntities,
                Tags       = tagsCollection
            };

            return(agileCrmServerContactEntity);
        }