public void AddWaiter(Waiters Item) { using (var context = new RestarauntContext()) { //add item to the dbContext var added = context.Waiters.Add(Item); //we arent going to do anything with the variable 'added' Just be aware that Add() method will return the newly added object. //This can be useful in other situations //Save changes to the database context.SaveChanges(); } }
public void DeleteWaiter(Waiters Item) { using (var context = new RestarauntContext()) { //first get a reference to the actual item in the db //find() is a method to lookup an item by its primary key var existing = context.Waiters.Find(Item.WaiterID); //second remove the item from the database context context.Waiters.Remove(existing); //lastly, save changes context.SaveChanges(); } }
public void UpdateWaiter(Waiters Item) { using (RestarauntContext context = new RestarauntContext()) { //first attach the item to the dbContext collection var attached = context.Waiters.Attach(Item); //second, get the entry for the existing data that should match for this specific special event var existing = context.Entry<Waiters>(attached); //third, mark that the objects values have changed existing.State = System.Data.Entity.EntityState.Modified; //lastly, save changes context.SaveChanges(); } }