public static ExportResponse UploadArtifactToSort(ArtifactData data) { ExportResponse rtn = new ExportResponse(); try { using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true })) { client.BaseAddress = new Uri(Config.SortUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsJsonAsync("api/Artifact/", data).Result; if (response.IsSuccessStatusCode) { var formatters = new List <MediaTypeFormatter>() { new JsonMediaTypeFormatter(), new XmlMediaTypeFormatter() }; rtn.SortId = response.Content.ReadAsAsync <int?>(formatters).Result; rtn.Success = true; } else { rtn.Success = false; rtn.ErrorMessage = $"Status Returned from API was : {response.StatusCode}"; } } } catch (Exception ex) { rtn.Success = false; rtn.ErrorMessage = ex.Message; rtn.StackTrace = ex.StackTrace; } return(rtn); }
public static ExportResponse RemoveArtifactFromSort(int sortId) { ExportResponse rtn = new ExportResponse(); try { using (var client = new HttpClient(new HttpClientHandler() { UseDefaultCredentials = true })) { //Post for new ID client.BaseAddress = new Uri(Config.SortUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.DeleteAsync("api/Artifact?id=" + sortId).Result; if (response.IsSuccessStatusCode) { rtn.Success = true; } else { rtn.Success = false; rtn.ErrorMessage = $"Status Returned from API was : {response.StatusCode}"; } } } catch (Exception ex) { rtn.Success = false; rtn.ErrorMessage = ex.Message; rtn.StackTrace = ex.StackTrace; } return(rtn); }