コード例 #1
0
 public static void DeleteOrder(tblOrder order)
 {
     try
     {
         using (dbPizzeriaEntities context = new dbPizzeriaEntities())
         {
             tblOrder orderToDelete = (from u in context.tblOrders where u.orderId == order.orderId select u).First();
             context.tblOrders.Remove(orderToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
コード例 #2
0
 public static int?GetTotalPrice(int orderId)
 {
     try
     {
         using (dbPizzeriaEntities context = new dbPizzeriaEntities())
         {
             int?result = (from x in context.vwOrders where x.orderId == orderId select x.totalPrice).FirstOrDefault();
             return(result);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
         return(null);
     }
 }
コード例 #3
0
 public static string GetPizzaName(int?dishId)
 {
     try
     {
         using (dbPizzeriaEntities context = new dbPizzeriaEntities())
         {
             string result = (from x in context.tblDishes where x.dishId == dishId select x.dishName).FirstOrDefault();
             return(result);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
         return(null);
     }
 }
コード例 #4
0
 public static List <tblOrder> GetOrdersByUsername(string username)
 {
     try
     {
         using (dbPizzeriaEntities context = new dbPizzeriaEntities())
         {
             List <tblOrder> result = (from x in context.tblOrders where x.username == username select x).ToList();
             return(result);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception " + ex.Message.ToString());
         return(null);
     }
 }
コード例 #5
0
 //read orders
 public static List <tblOrder> GetAllOrders()
 {
     try
     {
         using (dbPizzeriaEntities context = new dbPizzeriaEntities())
         {
             List <tblOrder> list = new List <tblOrder>();
             list = (from x in context.tblOrders select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
コード例 #6
0
 public static tblOrder AddNewOrder(tblOrder order)
 {
     try
     {
         using (dbPizzeriaEntities context = new dbPizzeriaEntities())
         {
             if (order.orderId == 0)
             {
                 //add
                 tblOrder newOrder = new tblOrder();
                 newOrder.status      = order.status;
                 newOrder.username    = order.username;
                 newOrder.dateAndTime = order.dateAndTime;
                 newOrder.dishId      = order.dishId;
                 newOrder.count       = order.count;
                 context.tblOrders.Add(newOrder);
                 context.SaveChanges();
                 order.orderId = newOrder.orderId;
                 return(order);
             }
             else
             {
                 //edit
                 tblOrder orderToEdit = (from x in context.tblOrders where x.orderId == order.orderId select x).FirstOrDefault();
                 orderToEdit.status = order.status;
                 context.SaveChanges();
                 return(order);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
         return(null);
     }
 }