private void GetItemsPollEvent(object src, ElapsedEventArgs e) { try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:3000"); httpWebRequest.Method = WebRequestMethods.Http.Get; httpWebRequest.Accept = "application/json"; var response = (HttpWebResponse)httpWebRequest.GetResponse(); using (var sr = new StreamReader(response.GetResponseStream())) { List <SmartCartItem> items = JsonConvert.DeserializeObject <List <SmartCartItem> >(sr.ReadToEnd()); foreach (var item in items) { if (!SmartCartItems.Contains(item)) { MainUserControlViewModel.AddSmartCartItem(item); } } Total = smartCartItems.Select(x => (x.Price * x.Count)).Sum(); } } catch (Exception ex) { AddLog(ex.Message, LogMessageType.ERROR); } }
private void Checkout() { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:3000/checkout"); httpWebRequest.Method = WebRequestMethods.Http.Get; httpWebRequest.Accept = "application/json"; var response = (HttpWebResponse)httpWebRequest.GetResponse(); using (var sr = new StreamReader(response.GetResponseStream())) { if (string.Equals(sr.ReadToEnd(), "CheckedOut")) { SmartCartItems.Clear(); Toast("Successfully paid " + Total.ToString() + "\nWe love your $$", ToastMessageType.Success); Total = 0; } } }
void AddSmartCartItemEventHandler(SmartCartItem item) { uiContext.Send(x => SmartCartItems.Add(item), null); }