public FreshdeskContact <TCustomFieldObject> ToContact()
        {
            var contact = new FreshdeskContact <TCustomFieldObject>
            {
                Active         = Active,
                Address        = Address,
                Avatar         = Avatar,
                CompanyId      = CompanyId ?? default(ulong),
                ViewAllTickets = ViewAllTickets ?? default(bool),
                Deleted        = Deleted,
                Description    = Description,
                Email          = Email,
                Id             = Id,
                JobTitle       = JobTitle,
                Language       = Language,
                Mobile         = Mobile,
                Name           = Name,
                Phone          = Phone,
                TimeZone       = TimeZone,
                TwitterId      = TwitterId,
                CreatedAt      = CreatedAt,
                UpdatedAt      = UpdatedAt,
                CustomFields   = CustomFields
            };

            if (OtherEmails != null && OtherEmails.Count > 0)
            {
                foreach (var otherEmail in OtherEmails)
                {
                    contact.OtherEmails.Add(otherEmail);
                }
            }
            if (Tags != null && Tags.Count > 0)
            {
                foreach (var tag in Tags)
                {
                    contact.Tags.Add(tag);
                }
            }
            if (OtherCompanies != null && OtherCompanies.Count > 0)
            {
                foreach (var otherCompany in OtherCompanies)
                {
                    contact.OtherCompanies.Add(otherCompany);
                }
            }
            return(contact);
        }
        public static FreshdeskContactInternalBase <TCustomFieldObject> FromContact(FreshdeskContact <TCustomFieldObject> contact)
        {
            ulong?companyId;

            if (contact.CompanyId == default(ulong))
            {
                companyId = null;
            }
            else
            {
                companyId = contact.CompanyId;
            }
            return(new FreshdeskContactInternalBase <TCustomFieldObject>
            {
                Active = contact.Active,
                Address = contact.Address,
                Avatar = contact.Avatar,
                CompanyId = companyId,
                ViewAllTickets = contact.ViewAllTickets,
                Deleted = contact.Deleted,
                Description = contact.Description,
                Email = contact.Email,
                Id = contact.Id,
                JobTitle = contact.JobTitle,
                Language = contact.Language,
                Mobile = contact.Mobile,
                Name = contact.Name,
                Phone = contact.Phone,
                TimeZone = contact.TimeZone,
                TwitterId = contact.TwitterId,
                CreatedAt = contact.CreatedAt,
                UpdatedAt = contact.UpdatedAt,
                OtherEmails = contact.OtherEmails,
                Tags = contact.Tags,
                OtherCompanies = contact.OtherCompanies,
                CustomFields = contact.CustomFields
            });
        }
Ejemplo n.º 3
0
        public async Task <FreshdeskContact <TCustomFieldObject> > UpdateAsync <TCustomFieldObject>(FreshdeskContact <TCustomFieldObject> contact) where TCustomFieldObject : class
        {
            var requestJson = JsonConvert.SerializeObject(FreshdeskContactInternal <TCustomFieldObject> .FromContact(contact), _serializationSettings);
            var requestUri  = $"{_apiBaseUri}/contacts/{contact.Id}";

            using (var requestContent = new StringContent(requestJson, Encoding.UTF8, "application/json"))
                using (var response = await _httpClient.PutAsync(requestUri, requestContent).ConfigureAwait(false))
                {
                    return((await GetResponseAsync <FreshdeskContactInternal <TCustomFieldObject> >(response).ConfigureAwait(false)).ToContact());
                }
        }