Пример #1
0
 /// <summary>
 /// If customer id is 0, they will be added. Otherwise, it will update based on the customer id
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static CustomerPurchase AddOrUpdate(CustomerPurchase p)
 {
     using (var context = new CustomerPurchaseContext())
     {
         context.Entry(p).State = (p.CustomerId == 0) ? EntityState.Added : EntityState.Modified;
         context.SaveChanges();
         return(p);
     }
 }
Пример #2
0
 public static CustomerPurchase Add(CustomerPurchase p)
 {
     using (var context = new CustomerPurchaseContext())
     {
         context.CustomerPurchases.Add(p);
         context.SaveChanges();
     }
     return(p);
 }
Пример #3
0
 /// <summary>
 /// Updates all customer purchase data (Except for customer id, which is the primary key)
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static CustomerPurchase Update(CustomerPurchase p)
 {
     using (var context = new CustomerPurchaseContext())
     {
         context.CustomerPurchases.Attach(p);
         context.Entry(p).State = EntityState.Modified;
         context.SaveChanges();
         return(p);
     }
 }
Пример #4
0
        /// <summary>
        /// Deletes a customer purchase from the database by their customer id
        /// </summary>
        /// <param name="p"></param>
        public static void Delete(CustomerPurchase p)
        {
            using (var context = new CustomerPurchaseContext())
            {
                context.CustomerPurchases.Add(p);

                context.Entry(p).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }