public static void AddNewMember(Member m) { var context = new CommerceDbContext(); context.Members.Add(m); context.SaveChanges(); }
public static void DeleteProduct(int id) { var context = new CommerceDbContext(); Product p = context.Products.Find(id); context.Products.Remove(p); context.SaveChanges(); }
public static void Update(Product p) { var context = new CommerceDbContext(); // tells EF this product has only been modified context.Entry(p).State = System.Data.Entity.EntityState.Modified; // send update querty to the database context.SaveChanges(); }
/// <summary> /// Add product to the database /// </summary> /// <param name="p">Product to be added</param> public static void AddProduct(Product p) { //Create instance of DBContext class var context = new CommerceDbContext(); //Prepare insert statement context.Products.Add(p); //Execute pending insert context.SaveChanges(); }