// Upload Item internal static async Task <Tuple <HttpStatusCode, Error> > CreateItemAsync(RootObjectItemCreate item) { HttpResponseMessage response = await client.PostAsJsonAsync( "ca/api/items", item); RootObjectError rootObjectError = new RootObjectError(); //response.EnsureSuccessStatusCode(); if (!response.IsSuccessStatusCode) { rootObjectError = await response.Content.ReadAsAsync <RootObjectError>(); } return(new Tuple <HttpStatusCode, Error>(response.StatusCode, rootObjectError.error)); }
// Create Item + status of API call // P.S. Authorization needed public async Task CreateItem(ItemCreate item) { Tuple <HttpStatusCode, Error> responce; try { // Login user await Login(); // If Login successfull, go on and create item if (LoginAPICallStatus == HttpStatusCode.OK) { // Wrap item with root element (for JSON formating during serialization) RootObjectItemCreate rootObjectItemCreate = new RootObjectItemCreate(item); responce = await IDMToolsAsync.CreateItemAsync(rootObjectItemCreate); // Get responce values CreateItemAPICallStatus = responce.Item1; CreateItemAPICallResponceError = responce.Item2; } // If not... do whatever you want, just not cry... take a candy ;) else { } } catch (Exception) { // handle Exception here throw; } finally { // Logout user await Logout(); } }