示例#1
0
        // GET: Items/Details/5
        public async Task <IActionResult> addBasket(int?id, string price)
        {
            int OrderID = Convert.ToInt32(Request.Cookies["IdOrder"]);

            //Cheak if adding new item to basket.
            if (id == 0 || _context.ItemsOrdered.Find(OrderID, id) != null || id == null)
            {
                return(View(await _context.Items.ToListAsync()));
            }
            //Pull information on order and customers, to update db with new items.

            _context.Orders.Find(OrderID).Price = price;
            ItemsOrdered Newitem = new ItemsOrdered();

            Newitem.IdItem   = Convert.ToInt32(id);
            Newitem.IdOrder  = OrderID;
            Newitem.Quantity = 1;
            _context.ItemsOrdered.Add(Newitem);

            if (ModelState.IsValid)
            {
                _context.SaveChanges();
            }

            string cookieValue = Request.Cookies["O"];

            if (cookieValue != null)
            {
                int value = Convert.ToInt32(cookieValue);
                value      += 1;
                cookieValue = value.ToString();
            }
            else
            {
                cookieValue = "1";
            }
            Response.Cookies.Append(id.ToString(), cookieValue);
            ViewBag.itemID = id;

            if (Request.Cookies["uniqueID"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            return(View(await _context.Items.ToListAsync()));
        }
示例#2
0
        //Opens an order that custmers can add to.
        private void OpenOrder(int idCustomer)
        {
            Orders        NewOrder     = new Orders();
            List <Orders> ListOfOrders = GetOrders();

            NewOrder.IdCustomer = idCustomer;
            NewOrder.IdOrder    = ListOfOrders.Count() + 1;
            NewOrder.Price      = "0";
            Response.Cookies.Append("IdOrder", NewOrder.IdOrder.ToString());
            NewOrder.Time = DateTime.Now.ToString("HH:mm");
            NewOrder.Date = DateTime.Now.ToString("MM/dd/yyyy");
            if (ModelState.IsValid)
            {
                _context.Add(NewOrder);
                _context.SaveChanges();
            }
        }