コード例 #1
0
 /// <summary>
 /// Deletes a server from the database
 /// </summary>
 /// <param name="server"></param>
 public static bool DeleteServer(Servers server)
 {
     using (var context = new OurRestaurantModel())
     {
         context.Servers.Add(server);
         context.Entry(server).State = EntityState.Deleted;
         int rowsAffected = context.SaveChanges();
         return(rowsAffected > 0);
     }
 }
コード例 #2
0
        /// <summary>
        /// Adds an individual transaction to the database
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static Transactions AddTransaction(Transactions order)
        {
            using (var context = new OurRestaurantModel())
            {
                /////////////////////////////////////
                // Need to keep for tracking items ALREADY IN database
                // Without this, items will be re-added to the database
                // with identical rows but for the ID column
                // DO NOT TAKE OUT
                foreach (var item in order.Products)
                {
                    context.Entry(item).State = EntityState.Unchanged;
                }
                context.Entry(order.Server).State = EntityState.Unchanged;
                /////////////////////////////////////

                context.Transactions.Add(order);
                context.SaveChanges();

                return(order);
            }
        }