public void Update(UpdateCustomerDemographicsView updateData, out string error) { error = null; try { Uri basePath = new Uri(wpfConfig.RESTBasePath); Uri requestUri = new Uri(basePath, "CustomerDemographics/Update"); GeneralBodyPost postRequest = new GeneralBodyPost(); postRequest.Data = updateData; string requestBody = JsonConvert.SerializeObject(postRequest); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Clear(); var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = requestUri, Content = new StringContent(requestBody, Encoding.UTF8, "application/json") }; var response = client.SendAsync(request).Result; var responseContent = response.Content; string responseString = responseContent.ReadAsStringAsync().Result; GeneralPostResponse generalPostResponse = null; GeneralErrorResponseContainer generalErrorResponse = null; base.ParseError(responseString, response, out error, out generalPostResponse, out generalErrorResponse); } } catch (Exception ex) { error = "Error trying post data. Request crash: " + ex.Message; } }
public IActionResult Delete(GeneralBodyPost GeneralBodyPost) { string transactionID = Guid.NewGuid().ToString(); string currentURL = this.Request.Method; HelperRestError helperRestError = new HelperRestError(); HelperHTTPLog helperHTTPLog = new HelperHTTPLog(HelperHTTPLog.WhatToLog.All); try { GeneralPostResponse resultContainer = new GeneralPostResponse(); resultContainer.ReportPostHeader.TransactionID = transactionID; RestExceptionError restExceptionError = null; RESTSuppliersDB rESTSuppliersDB = new RESTSuppliersDB(base.RESTConfig); DeleteSuppliersView viewToDelete = rESTSuppliersDB.TryParse <DeleteSuppliersView>(GeneralBodyPost, out restExceptionError); if (restExceptionError != null) { CreatedResult errorResult = helperRestError.GetError412_PreConditionFailed(transactionID, restExceptionError.ExceptionMessage, restExceptionError.InternalMessage, "Suppliers/Insert"); return(errorResult); } rESTSuppliersDB.TryDelete(viewToDelete, out restExceptionError); if (restExceptionError != null) { CreatedResult errorResult = helperRestError.GetError500_InternalServerError(transactionID, restExceptionError.ExceptionMessage, restExceptionError.InternalMessage, "Suppliers/GetAll"); return(errorResult); } resultContainer.ReportPostHeader.Message = "Success"; HttpResponseMessage httpResponseMessage = new HttpResponseMessage(); httpResponseMessage.StatusCode = System.Net.HttpStatusCode.OK; CreatedResult createdResult = new CreatedResult("Suppliers/Delete", httpResponseMessage); createdResult.Value = resultContainer; createdResult.StatusCode = 200; return(createdResult); } catch (Exception ex) { CreatedResult errorResult = helperRestError.GetError500_InternalServerError(transactionID, ex.Message, "x", "Suppliers/Create"); return(errorResult); } }