/// <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); }
/// <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); }