public async Task <HttpResponseMessage> AddNewLocker(NewLockerRequest req) { this._client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Constants.Token); var jsonToSend = JsonConvert.SerializeObject(req); var content = new StringContent(jsonToSend, Encoding.UTF8, Constants.Headers.ContentType); var result = await this._api.AddNewLocker(Constants.Headers.ContentType, content); return(result); }
public async Task <ResponseData <LockerInfo> > AddNewLocker(string newLockerId) { var newLockerRequest = new NewLockerRequest(); newLockerRequest.LockerId = newLockerId; ; var responseData = new ResponseData <LockerInfo> { HasBeenSuccessful = false }; var result = await this._apiWrapper.AddNewLocker(newLockerRequest); string content = await result.Content.ReadAsStringAsync(); if (result.StatusCode == HttpStatusCode.OK) { try { var deserializedContent = JsonConvert.DeserializeObject <ResponseData <LockerInfo> >(content); if (deserializedContent.HasBeenSuccessful == false) { responseData.HasBeenSuccessful = false; responseData.Error = deserializedContent.Error; responseData.Content = null; return(responseData); } responseData.HasBeenSuccessful = true; responseData.Error = null; responseData.Content = deserializedContent.Content; return(responseData); } catch (Exception e) { Console.WriteLine(e.StackTrace); responseData.HasBeenSuccessful = false; responseData.Error = "Deserialization Error"; responseData.Content = null; return(responseData); } } else { responseData.HasBeenSuccessful = false; responseData.Error = "Internal server error"; responseData.Content = null; return(responseData); } }