コード例 #1
0
ファイル: Contacts.cs プロジェクト: synewaves/harvest.net
        /// <summary>
        /// Create a new contact for a client on the authenticated account. Makes both a POST and a GET request to the Contacts resource.
        /// </summary>
        /// <param name="clientId">The ID of the client this contact is for</param>
        /// <param name="firstName">The first name of the contact</param>
        /// <param name="lastName">The last name of the contact</param>
        /// <param name="title">The contact's title</param>
        /// <param name="email">The contact's email</param>
        /// <param name="phoneOffice">The contact's office phone number</param>
        /// <param name="phoneMobile">The contact's mobile phone number</param>
        /// <param name="fax">The contact's fax number</param>
        public Contact CreateContact(long clientId, string firstName, string lastName, string title = null, string email = null, string phoneOffice = null, string phoneMobile = null, string fax = null)
        {
            if (firstName == null)
            {
                throw new ArgumentNullException("firstName");
            }

            if (lastName == null)
            {
                throw new ArgumentNullException("lastName");
            }

            var newContact = new ContactOptions()
            {
                ClientId    = clientId,
                FirstName   = firstName,
                LastName    = lastName,
                Title       = title,
                Email       = email,
                PhoneOffice = phoneOffice,
                PhoneMobile = phoneMobile,
                Fax         = fax
            };

            return(CreateContact(newContact));
        }
コード例 #2
0
        private IRestRequest UpdateContactRequest(long contactId, ContactOptions options)
        {
            var request = Request($"{ContactsResource}/{contactId}", RestSharp.Method.PUT);

            request.AddBody(options);

            return(request);
        }
コード例 #3
0
ファイル: Contacts.cs プロジェクト: synewaves/harvest.net
        /// <summary>
        /// Update an existing contact on the authenticated account. Makes both a PUT and GET request to the Contacts resource.
        /// </summary>
        /// <param name="contactId">The ID of the contact to update</param>
        /// <param name="options">The update options for the contact</param>
        public Contact UpdateContact(long contactId, ContactOptions options)
        {
            var request = Request("contacts/" + contactId, RestSharp.Method.PUT);

            request.AddBody(options);

            return(Execute <Contact>(request));
        }
コード例 #4
0
        private IRestRequest CreateContactRequest(ContactOptions options)
        {
            var request = Request($"{ContactsResource}", RestSharp.Method.POST);

            request.AddBody(options);

            return(request);
        }
コード例 #5
0
ファイル: Contacts.cs プロジェクト: synewaves/harvest.net
        /// <summary>
        /// Creates a new contact under the authenticated account. Makes a POST and a GET request to the Contacts resource.
        /// </summary>
        /// <param name="options">The options for the new contact to be created</param>
        public Contact CreateContact(ContactOptions options)
        {
            var request = Request("contacts", RestSharp.Method.POST);

            request.AddBody(options);

            return(Execute <Contact>(request));
        }
コード例 #6
0
ファイル: Contacts.cs プロジェクト: zBrianW/harvest.net
        private static ContactOptions GetContactOptions(long?clientId, string firstName, string lastName, string title, string email, string phoneOffice, string phoneMobile, string fax)
        {
            var newContact = new ContactOptions
            {
                ClientId    = clientId,
                FirstName   = firstName,
                LastName    = lastName,
                Title       = title,
                Email       = email,
                PhoneOffice = phoneOffice,
                PhoneMobile = phoneMobile,
                Fax         = fax
            };

            return(newContact);
        }
コード例 #7
0
ファイル: Contacts.cs プロジェクト: synewaves/harvest.net
        /// <summary>
        /// Update an existing contact on the authenticated account. Makes both a PUT and GET request to the Contacts resource.
        /// </summary>
        /// <param name="contactId">The ID of the contact to update</param>
        /// <param name="clientId">The ID of the client this contact is for</param>
        /// <param name="firstName">The first name of the contact</param>
        /// <param name="lastName">The last name of the contact</param>
        /// <param name="title">The contact's title</param>
        /// <param name="email">The contact's email</param>
        /// <param name="phoneOffice">The contact's office phone number</param>
        /// <param name="phoneMobile">The contact's mobile phone number</param>
        /// <param name="fax">The contact's fax number</param>
        public Contact UpdateContact(long contactId, long?clientId = null, string firstName = null, string lastName = null, string title = null, string email = null, string phoneOffice = null, string phoneMobile = null, string fax = null)
        {
            var options = new ContactOptions()
            {
                ClientId    = clientId,
                FirstName   = firstName,
                LastName    = lastName,
                Title       = title,
                Email       = email,
                PhoneOffice = phoneOffice,
                PhoneMobile = phoneMobile,
                Fax         = fax
            };

            return(UpdateContact(contactId, options));
        }
コード例 #8
0
        /// <summary>
        /// Update an existing contact on the authenticated account. Makes both a PUT and GET request to the Contacts resource.
        /// </summary>
        /// <param name="contactId">The ID of the contact to update</param>
        /// <param name="options">The update options for the contact</param>
        public Contact UpdateContact(long contactId, ContactOptions options)
        {
            var request = UpdateRequest(CONTACTS_RESOURCE, contactId, options);

            return(Execute <Contact>(request));
        }
コード例 #9
0
        /// <summary>
        /// Creates a new contact under the authenticated account. Makes a POST and a GET request to the Contacts resource.
        /// </summary>
        /// <param name="options">The options for the new contact to be created</param>
        public Task <Contact> CreateContactAsync(ContactOptions options)
        {
            var request = CreateRequest(CONTACTS_RESOURCE, options);

            return(ExecuteAsync <Contact>(request));
        }
コード例 #10
0
        /// <summary>
        /// Creates a new contact under the authenticated account. Makes a POST and a GET request to the Contacts resource.
        /// </summary>
        /// <param name="options">The options for the new contact to be created</param>
        public Contact CreateContact(ContactOptions options)
        {
            var request = CreateRequest(CONTACTS_RESOURCE, options);

            return(Execute <Contact>(request));
        }
コード例 #11
0
 /// <summary>
 /// Update an existing contact on the authenticated account. Makes both a PUT and GET request to the Contacts resource.
 /// </summary>
 /// <param name="contactId">The ID of the contact to update</param>
 /// <param name="options">The update options for the contact</param>
 public async Task <Contact> UpdateContactAsync(long contactId, ContactOptions options, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await ExecuteAsync <Contact>(UpdateContactRequest(contactId, options), cancellationToken));
 }
コード例 #12
0
 /// <summary>
 /// Update an existing contact on the authenticated account. Makes both a PUT and GET request to the Contacts resource.
 /// </summary>
 /// <param name="contactId">The ID of the contact to update</param>
 /// <param name="options">The update options for the contact</param>
 public Contact UpdateContact(long contactId, ContactOptions options)
 {
     return(Execute <Contact>(UpdateContactRequest(contactId, options)));
 }
コード例 #13
0
 /// <summary>
 /// Creates a new contact under the authenticated account. Makes a POST and a GET request to the Contacts resource.
 /// </summary>
 /// <param name="options">The options for the new contact to be created</param>
 public Contact CreateContact(ContactOptions options)
 {
     return(Execute <Contact>(CreateContactRequest(options)));
 }
コード例 #14
0
        /// <summary>
        /// Updates an existing contact from the sevDesk API.
        /// </summary>
        /// <param name="id">The ID of the contact.</param>
        /// <param name="options">The options that contain the information about the contact.</param>
        /// <exception cref="InvalidOperationException">If the API could not be reached or the token is not valid, an <see cref="InvalidOperationException" /> is thrown.</exception>
        /// <returns>Returns the updated contact.</returns>
        public async Task <Contact> UpdateContactAsync(string id, ContactOptions options)
        {
            try
            {
                // Initializes the key value pairs
                List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >();
                if (!string.IsNullOrWhiteSpace(options.CustomerNumber))
                {
                    values.Add(new KeyValuePair <string, string>("customerNumber", options.CustomerNumber));
                }
                if (!string.IsNullOrWhiteSpace(options.Description))
                {
                    values.Add(new KeyValuePair <string, string>("description", options.Description));
                }
                if (!string.IsNullOrWhiteSpace(options.CategoryId))
                {
                    values.Add(new KeyValuePair <string, string>("category[id]", options.CategoryId));
                    values.Add(new KeyValuePair <string, string>("category[objectName]", "Category"));
                }

                // Adds the specific properties of a person
                PersonOptions personOptions = options as PersonOptions;
                if (personOptions != null)
                {
                    if (!string.IsNullOrWhiteSpace(personOptions.FirstName))
                    {
                        values.Add(new KeyValuePair <string, string>("surename", personOptions.FirstName));
                    }
                    if (!string.IsNullOrWhiteSpace(personOptions.LastName))
                    {
                        values.Add(new KeyValuePair <string, string>("familyname", personOptions.LastName));
                    }
                    if (!string.IsNullOrWhiteSpace(personOptions.AcademicTitle))
                    {
                        values.Add(new KeyValuePair <string, string>("academicTitle", personOptions.AcademicTitle));
                    }
                    if (!string.IsNullOrWhiteSpace(personOptions.Position))
                    {
                        values.Add(new KeyValuePair <string, string>("titel", personOptions.Position));
                    }
                    if (personOptions.Birthday != null)
                    {
                        values.Add(new KeyValuePair <string, string>("birthday", personOptions.Birthday?.ToString("yyyy-MM-ddT00:00:00")));
                    }
                    values.Add(new KeyValuePair <string, string>("gender", personOptions.Gender == Gender.Male ? "m" : "w"));
                    if (!string.IsNullOrWhiteSpace(personOptions.OrganizationId))
                    {
                        values.Add(new KeyValuePair <string, string>("parent[id]", personOptions.OrganizationId));
                        values.Add(new KeyValuePair <string, string>("parent[objectName]", "Contact"));
                    }
                }

                // Adds the specific properties of an organization
                OrganizationOptions organizationOptions = options as OrganizationOptions;
                if (organizationOptions != null)
                {
                    if (!string.IsNullOrWhiteSpace(organizationOptions.Name))
                    {
                        values.Add(new KeyValuePair <string, string>("name", organizationOptions.Name));
                    }
                }

                // Sends an HTTP request to endpoint
                HttpResponseMessage response = await httpClient.PutAsync($"{this.apiUri}/Contact/{id}?token={this.Token}", new FormUrlEncodedContent(values));

                // Returns the updated contact
                return(this.GetContact(JsonConvert.DeserializeObject <Result <Models.Contacts.Contact> >(await response.Content.ReadAsStringAsync()).objects));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(e.Message, e);
            }
        }
コード例 #15
0
 public ContactModel(IOptions <ContactOptions> options, Repository <Household> householdRepository)
 {
     this.Contact             = options.Value;
     this.householdRepository = householdRepository;
 }
コード例 #16
0
        /// <summary>
        /// Update an existing contact on the authenticated account. Makes both a PUT and GET request to the Contacts resource.
        /// </summary>
        /// <param name="contactId">The ID of the contact to update</param>
        /// <param name="options">The update options for the contact</param>
        public Task <Contact> UpdateContactAsync(long contactId, ContactOptions options)
        {
            var request = UpdateRequest(CONTACTS_RESOURCE, contactId, options);

            return(ExecuteAsync <Contact>(request));
        }
コード例 #17
0
 public HomeController(Services.Smtp smtpService, IOptions <ContactOptions> contactOptions)
 {
     _smtpService    = smtpService;
     _contactOptions = contactOptions.Value;
 }
コード例 #18
0
 /// <summary>
 /// Creates a new contact under the authenticated account. Makes a POST and a GET request to the Contacts resource.
 /// </summary>
 /// <param name="options">The options for the new contact to be created</param>
 public async Task <Contact> CreateContactAsync(ContactOptions options, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await ExecuteAsync <Contact>(CreateContactRequest(options), cancellationToken));
 }