示例#1
0
        public async Task <JsonResult> DeliveryOrder(int id)
        {
            try
            {
                Orders orders = await _orderrepository.GetBy(id);

                orders.Status = 1;

                //Trừ số lượng bánh khi giao hàng
                _orderrepository.UpdateBakeryQuantity(orders);

                _context.Orders.Update(orders);
                _context.SaveChanges();

                return(Json(new
                {
                    status = true
                }));
            }
            catch
            {
                return(Json(new
                {
                    status = false
                }));
            }
        }
示例#2
0
        public void CreateOrder(Orders orders)
        {
            orders.CreateDate = DateTime.Now;
            _context.Orders.Add(orders);
            _context.SaveChanges();
            var shoppingCartItems = _shoppingCart.GetShoppingCartItem();

            foreach (var item in shoppingCartItems)
            {
                var orderDetail = new OrderDetail()
                {
                    Quantity = item.Amount,
                    Idbakery = (int)item.Idbakery,
                    Idorder  = orders.Id,
                    Total    = item.Amount * item.IdbakeryNavigation.Price
                };
                _context.OrderDetail.Add(orderDetail);
            }
            _context.SaveChanges();
        }