/// <inheritdoc /> public async Task UpdateAsync(long companyId, AgileCrmCompanyRequest agileCrmCompanyModel) { const string MethodName = nameof(this.UpdateAsync); this.logger.LogMethodStart(ClassName, MethodName); try { // Validate argument object agileCrmCompanyModel.ValidateModel(); // Serialize object to JSON var companyEntityBase = agileCrmCompanyModel.ToCompanyEntityBase(); companyEntityBase.Id = companyId; var stringContent = companyEntityBase.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.Company, companyId); this.logger.LogMethodEnd(ClassName, MethodName); }
/// <inheritdoc /> public async Task CreateAsync(AgileCrmCompanyRequest agileCrmCompanyModel) { const string MethodName = nameof(this.CreateAsync); this.logger.LogMethodStart(ClassName, MethodName); var companyId = default(long); try { // Validate argument object agileCrmCompanyModel.ValidateModel(); // Serialize object to JSON var companyEntityBase = agileCrmCompanyModel.ToCompanyEntityBase(); var stringContent = companyEntityBase.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); companyId = httpContentAsString.DeserializeJson(new { id = default(long) }).id; } catch (Exception exception) { this.logger.LogException(ClassName, MethodName, exception); throw; } this.logger.LogCreated(ServiceType.Company, companyId); this.logger.LogMethodEnd(ClassName, MethodName); }