示例#1
0
 public static void DeleteCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);
         context.Entry(c).State = EntityState.Deleted;
         int rowsAffecteed = context.SaveChanges();
     }
 }
 /// <summary>
 /// Add's a customer. Return's newly added customer
 /// with the CustomerId populated.
 /// </summary>
 /// <param name="c">New Customer to be added.</param>
 /// <returns></returns>
 public static Customer AddCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);
         context.SaveChanges();
         return c;
     }
 }
 public static Customer UpdateCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);
         context.Entry(c).State = EntityState.Modified;
         context.SaveChanges();
         return c;
     }
 }
示例#4
0
 /// <summary>
 /// Adds a customer. Returns the newly added customer with the CustomerID populated.
 /// </summary>
 /// <param name="c">The new customer</param>
 /// <returns></returns>
 public static Customer AddCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);
         //save changes MUST be called with inserts, updates, and deletes
         context.SaveChanges();
         return(c);
     }
 }
示例#5
0
 public static Customer UpdateCustomer(Customer c)
 {
     using (var context = new BookRegistrationEntities())
     {
         context.Customer.Add(c);
         // Tell EF we are updating an existing entity
         context.Entry(c).State = EntityState.Modified;
         context.SaveChanges();
         return(c);
     }
 }
示例#6
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);
                context.SaveChanges();
                // Return newly added customer with CustomerID populated

                return(c);
            }
        }
示例#7
0
 /// <summary>
 /// Adds a customer. Returns the newly added customer with the Customer Id 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);
         //Save changes must be called for INSERTS UPDATES and DELETES
         context.SaveChanges();
         //Return newly added customer with CustomerId(Identity column) populated
         return(c);
     }
 }
        /// <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);

                // Save changes must be called for insert/update/delete
                context.SaveChanges();
                // Return newly added customer with customer id populated.
                return(c);
            }
        }
        /// <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 (Identity column) populated
                return(c);
            }
        }
示例#10
0
 public static Customer UpdateCustomer(Customer c)
 {
     // If a customer ID = 0 EF will know this is a new customer.
     using (var context = new BookRegistrationEntities())
     {
         //Adds to context, not DB(technically) so it starts tracking it
         context.Customer.Add(c);
         //Tell EF we are updating an existing entity
         context.Entry(c).State = EntityState.Modified;
         context.SaveChanges();
         return(c);
     }
 }