Example #1
0
 /// <summary>
 /// 新增訂單
 /// </summary>
 /// <param name="order"></param>
 public void InsertOrder(Models.Order order)
 {
     using (Models.originalDB db = new Models.originalDB())
     {
         int max = db.Orders.Select(x => x.OrderID).Max();
         order.OrderID = max + 1;
         db.Orders.Add(order);
         db.SaveChanges();
     }
 }
Example #2
0
        /// <summary>
        /// 刪除訂單明細
        /// </summary>
        public void DeleteOrderDetailById(int orderId, int productId)
        {
            using (Models.originalDB db = new Models.originalDB())
            {
                //List<Models.OrderDetail> dbOrderDetails = db.OrderDetails.Select(x => new Models.Order { ProductID = x.ProductID, OrderID = x.OrderID }).Where(y => (y.OrderID == orderId) && (y.ProductID == productId)).ToList();

                int[] par = new int[2];
                par[0] = orderId;
                par[1] = productId;
                var deleteRow = db.OrderDetails.Find(orderId, productId);

                db.OrderDetails.Remove(deleteRow);

                db.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// 刪除訂單
        /// </summary>
        public void DeleteOrderById(int orderId)
        {
            using (Models.originalDB db = new Models.originalDB())
            {
                var deleteRow = db.Orders.Find(orderId);
                foreach (var orderDetail in deleteRow.OrderDetails)
                {
                    //  DeleteOrderDetailById(orderDetail.OrderID, orderDetail.ProductID);
                }

                //  deleteRow.OrderDetails = new HashSet<Models.OrderDetail>();


                db.Orders.Remove(deleteRow);
                db.SaveChanges();
            }
        }
Example #4
0
 /// <summary>
 /// 更新訂單
 /// </summary>
 /// <param name="訂單"></param>
 public void UpdateOrder(Models.Order oneOrder)
 {
     using (Models.originalDB db = new Models.originalDB())
     {
         Models.Order dbOrders = db.Orders.Find(oneOrder.OrderID);
         dbOrders.CustomerID     = oneOrder.CustomerID;
         dbOrders.EmployeeID     = oneOrder.EmployeeID;
         dbOrders.Freight        = (decimal)oneOrder.Freight;
         dbOrders.OrderDate      = (DateTime)oneOrder.OrderDate;
         dbOrders.RequiredDate   = (DateTime)oneOrder.RequiredDate;
         dbOrders.ShipAddress    = oneOrder.ShipAddress;
         dbOrders.ShipCity       = oneOrder.ShipCity;
         dbOrders.ShipCountry    = oneOrder.ShipCountry;
         dbOrders.ShipName       = oneOrder.ShipName;
         dbOrders.ShippedDate    = oneOrder.ShippedDate;
         dbOrders.ShipperID      = oneOrder.ShipperID;
         dbOrders.ShipPostalCode = oneOrder.ShipPostalCode;
         dbOrders.ShipRegion     = oneOrder.ShipRegion;
         dbOrders.OrderDetails   = oneOrder.OrderDetails;
         var a = db.SaveChanges();
     }
 }