public IActionResult OnPost() { List <int> items = new List <int>(); StringValues sv; Request.Form.TryGetValue("item", out sv); foreach (string str in sv.ToArray()) { items.Add(Int32.Parse(str)); } Order o = new Order(); o.comment = ""; o.idTable = 1; o.id = -1; o.receipt = ""; o.status = "PENDING"; o.items = items.ToArray(); string os = JsonConvert.SerializeObject(o); SocketSession ss = new SocketSession(); ss.Send("SUBMITORDER|" + os); string r = ss.Receive(); Console.WriteLine(r); Console.WriteLine(os); Response.Cookies.Delete("orderid"); Response.Cookies.Append("orderid", r); Response.Cookies.Delete("cart"); return(RedirectToPage("/Receipt")); }
public void OnGet() { SocketSession ss = new SocketSession(); ss.Send("GETMENUITEMS"); string r = ss.Receive(); string[] rs = r.Split(new char[] { '|' }); menuItems = new MenuItem[rs.Length]; int j = 0; foreach (string ms in rs) { MenuItem m = JsonConvert.DeserializeObject <MenuItem>(ms); menuItems[j++] = m; } if (Request.Cookies.ContainsKey("cart")) { cartLogo = "/lib/img/cart.png"; } else { cartLogo = "/lib/img/cart_gray.png"; } }
public void OnGet() { if (Request.Cookies.ContainsKey("cart")) { cartLogo = "/lib/img/cart.png"; } else { cartLogo = "/lib/img/cart_gray.png"; } SocketSession ss = new SocketSession(); ss.Send("GETMENUITEMS"); string r = ss.Receive(); string[] rs = r.Split(new char[] { '|' }); MenuItem[] allItems = new MenuItem[rs.Length]; int j = 0; foreach (string str in rs) { allItems[j++] = JsonConvert.DeserializeObject <MenuItem>(str); } string c; bool b = Request.Cookies.TryGetValue("cart", out c); if (!b) { cartItems = new MenuItem[0]; return; } string[] cs = c.Split(new char[] { ',' }); cartItems = new MenuItem[cs.Length]; j = 0; totalSum = 0; foreach (string str in cs) { int i = Int32.Parse(str); foreach (MenuItem mi in allItems) { if (mi.id == i) { cartItems[j++] = mi; totalSum += mi.price; } } } }