Ejemplo n.º 1
0
        public FreshdeskContactDto GetContact(long contactId)
        {
            string responseBody         = String.Empty;
            FreshdeskContactDto contact = null;


            HttpWebRequest request = FreshdeskHttpClient.GetRequestMessage("GET",
                                                                           $"/api/v2/contacts/{contactId}");

            try
            {
                responseBody = GetRequest(request);

                if (!string.IsNullOrEmpty(responseBody))
                {
                    contact = JsonConvert.DeserializeObject <FreshdeskContactDto>(responseBody);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(contact);
        }
Ejemplo n.º 2
0
        public Guid?CreateContact(long contactId)
        {
            Guid?contactGuid = null;
            FreshdeskContactDto freshdeskContactDto = _freshdeskRepo.GetContact(contactId);

            if (freshdeskContactDto != null)
            {
                Entity contactEntity = _contactMapper.CreateContact(freshdeskContactDto);

                if (contactEntity != null)
                {
                    var result = UpsertContact(contactEntity);

                    contactGuid = result.EntityId;
                }
            }

            return(contactGuid);
        }
Ejemplo n.º 3
0
        public FreshdeskContactDto CreateContact(FreshdeskContactForCreation freshdeskContactForCreation)
        {
            FreshdeskContactDto freshdeskContactDto = null;

            string         responseBody = String.Empty;
            HttpWebRequest request      = FreshdeskHttpClient.GetRequestMessage("POST",
                                                                                $"/api/v2/contacts");

            string data = JsonConvert.SerializeObject(freshdeskContactForCreation);

            byte[] byteArray = Encoding.UTF8.GetBytes(data);
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            responseBody = WriteRequest(request, byteArray);

            freshdeskContactDto = JsonConvert.DeserializeObject <FreshdeskContactDto>(responseBody);

            return(freshdeskContactDto);
        }
Ejemplo n.º 4
0
        public Entity CreateContact(FreshdeskContactDto freshdeskContactDto)
        {
            Entity contact = new Entity("contact");

            contact["isw_freshdeskid"] = freshdeskContactDto.Id.ToString();

            if (freshdeskContactDto.CompanyId != null)
            {
                string[]            columns = { "accountid" };
                ConditionExpression ce      = new ConditionExpression("isw_freshdeskid", ConditionOperator.Equal, freshdeskContactDto.CompanyId.ToString());

                FilterExpression fe = new FilterExpression();
                fe.AddCondition(ce);

                var ec = CrmServiceFactory.RetrieveEntities("account", columns, fe, 1);

                if (ec.Entities.Count > 0)
                {
                    contact.Attributes["parentcustomerid"] = new EntityReference(ec.Entities[0].LogicalName, ec.Entities[0].Id);
                }
            }

            if (!string.IsNullOrEmpty(freshdeskContactDto.Email))
            {
                contact["emailaddress1"] = freshdeskContactDto.Email;
            }

            if (!string.IsNullOrEmpty(freshdeskContactDto.Name))
            {
                string[] nameSplit = freshdeskContactDto.Name.Split(' ');

                contact["firstname"] = nameSplit[0];

                if (nameSplit.Length > 1)
                {
                    contact["lastname"] = nameSplit[1];
                }
            }
            contact["telephone1"] = freshdeskContactDto.Phone;

            if (!string.IsNullOrEmpty(freshdeskContactDto.Description))
            {
                contact["description"] = freshdeskContactDto.Description;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.Address))
            {
                contact["address1_line1"] = freshdeskContactDto.Address;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.JobTitle))
            {
                contact["jobtitle"] = freshdeskContactDto.JobTitle;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.Mobile))
            {
                contact["telephone2"] = freshdeskContactDto.Mobile;
            }
            if (!string.IsNullOrEmpty(freshdeskContactDto.Name))
            {
                contact["fullname"] = freshdeskContactDto.Name;
            }


            return(contact);
        }