Beispiel #1
0
 public static void DeleteCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);                      // "Track" with EF
         context.Entry(c).State = EntityState.Deleted; // Tell EF we are removing it
         int rowsAffected = context.SaveChanges();     // Update on database
         // int rowsAffected is optional
     }
 }
Beispiel #2
0
 public static Customer UpdateCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);                       // Add to context
         // Tell EF we are updating an existing entity
         context.Entry(c).State = EntityState.Modified; // Tell EF it has been modified
         context.SaveChanges();
         return(c);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Adds a customer. Returns the newly added customer
        /// with the CustomerID populated
        /// </summary>
        /// <param name="c">The new Customer to be added</param>
        /// <returns></returns>
        public static Customer AddCustomer(Customer c)
        {
            using (var context = new BookRegistrationEntities())
            {
                context.Customer.Add(c);
                // SaveChanges MUST BE CALLED for insert/update/delete
                context.SaveChanges();

                // Return newly added customer with CustomerID populated
                return(c);
            }
        }