// ReSharper disable once InconsistentNaming /// <summary> /// CRUD CREATE /// </summary> /// <typeparam name="T">The response type</typeparam> /// <typeparam name="R">The body parameter type</typeparam> /// <param name="address">The URI.</param> /// <param name="entity">The body entity.</param> /// <param name="parameters">The query string parameters.</param> /// <returns>A result object that wraps the parsed response and an error if something not right happened</returns> protected async Task <IResult <R> > PostInternal <T, R>(string address, T entity, Dictionary <string, string> parameters = null) where T : class where R : class { R result = null; string paymentRef = ""; if (_deDuplicateTransactions) { Type t = entity.GetType(); PropertyInfo prop = t.GetRuntimeProperty("YourPaymentReference"); paymentRef = (string)prop.GetValue(entity); if (!string.IsNullOrEmpty(paymentRef)) { IResponse <R> oldResponse = DeDuplicate(paymentRef) as IResponse <R>; if (oldResponse != null) { result = oldResponse.ResponseBodyObject; return(new Result <R>(result, oldResponse.JudoError)); } } } Dictionary <string, string> extraHeaders = null; IModelWithHttpHeaders headersModel = entity as IModelWithHttpHeaders; if (headersModel != null && headersModel.HttpHeaders.Count > 0) { extraHeaders = headersModel.HttpHeaders; } var response = await _client.Post <R>(address, parameters, extraHeaders, entity).ConfigureAwait(false); if (!response.ErrorResponse) { if (this._deDuplicateTransactions && !string.IsNullOrEmpty(paymentRef)) { this.StoreResult(response, paymentRef); } result = response.ResponseBodyObject; } return(new Result <R>(result, response.JudoError)); }
// ReSharper disable once InconsistentNaming /// <summary> /// CRUD UPDATE /// </summary> /// <typeparam name="T">The response type</typeparam> /// <typeparam name="R">The body parameter type</typeparam> /// <param name="address">The URI.</param> /// <param name="entity">The body entity.</param> /// <param name="parameters">The query string parameters.</param> /// <returns>A result object that wraps the parsed response and an error if something not right happened</returns> protected async Task <IResult <R> > PutInternal <T, R>(string address, T entity, Dictionary <string, string> parameters = null) where T : class where R : class { Dictionary <string, string> extraHeaders = null; IModelWithHttpHeaders headersModel = entity as IModelWithHttpHeaders; if (headersModel != null && headersModel.HttpHeaders.Count > 0) { extraHeaders = headersModel.HttpHeaders; } R result = null; var response = await _client.Update <R>(address, parameters, extraHeaders, entity).ConfigureAwait(false); if (!response.ErrorResponse) { result = response.ResponseBodyObject; } return(new Result <R>(result, response.JudoError)); }