public static void LogException(Exception exception) { ServiceInputObject inputObject = new ServiceInputObject { baseURL = ConfigSettings.WebApiBaseAddress, controllerName = "ProjectException", methodName = "PostException" }; ProjectExceptionEntities generatedException = new ProjectExceptionEntities(); generatedException.CreatedDate = DateTime.Now; generatedException.Message = exception.Message; generatedException.ProjectType = Convert.ToString(ProjectTypeEnum.ServiceLayer); generatedException.StackTrace = exception.StackTrace; ServiceMethods.GeneratePostRequestWithIntDestinationEntity <ProjectExceptionEntities>(generatedException, inputObject); }
public static int GenerateDeleteRequest(int idToDelete, ServiceInputObject serviceInputObect) { try { HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(serviceInputObect.baseURL); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = httpClient.DeleteAsync(serviceInputObect.finalUrlStringForDelete).Result; if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <int>(response.Content.ReadAsStringAsync().Result)); } else { throw new ServiceExceptions(response.ReasonPhrase); } } catch (Exception ex) { throw ex; } }
public static int GeneratePostRequestWithIntDestinationEntity <TSourceEntity>(TSourceEntity sourceEntity, ServiceInputObject serviceInputObect) where TSourceEntity : class { try { HttpClient httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(serviceInputObect.baseURL); httpClient.DefaultRequestHeaders.Accept.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = httpClient.PostAsJsonAsync(serviceInputObect.finalUrlStringForPost, sourceEntity).Result; if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <int>(response.Content.ReadAsStringAsync().Result)); } else { throw new ServiceExceptions(response.ReasonPhrase); } } catch (Exception ex) { throw ex; } }