private async Task <List <StockSnapModel> > GetStockLookups() { try { if (App.CheckInternetConnection()) { HttpClient client = new HttpClient() { BaseAddress = new Uri(App.baseUrl) }; StockSnapModel model = new StockSnapModel() { UserId = userId, DeviceId = deviceId, ItemName = string.Empty, }; string jsonData = JsonConvert.SerializeObject(model); var content = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync(App.getStockSnapsUri, content).ConfigureAwait(false); if (response != null && response.IsSuccessStatusCode) { var result = await response.Content.ReadAsStringAsync(); retValue = JsonConvert.DeserializeObject <List <StockSnapModel> >(result); } } else { await DisplayAlert("Alert", "No internet connection", "Exit"); System.Diagnostics.Process.GetCurrentProcess().Kill(); System.Environment.Exit(0); } } catch (Exception ex) { await DisplayAlert("Error", ex.Message, "Exit"); System.Diagnostics.Process.GetCurrentProcess().Kill(); System.Environment.Exit(0); } return(retValue); }
public HttpResponseMessage GetStockSnaps([FromBody] StockSnapModel model) { HttpResponseMessage retValue = null; using (retValue = new HttpResponseMessage(HttpStatusCode.InternalServerError)) { try { if (model != null) { List <Models.StockSnapModel> snapModel = GetStockSnaps(model.UserId, model.ItemName); retValue = Request.CreateResponse(HttpStatusCode.OK, snapModel); } } catch (Exception ex) { new Logger().LogException(ex, "GetStockSnaps"); retValue = Request.CreateResponse(HttpStatusCode.OK, ex.Message); } return(retValue); } }