public List<CategoryDTO> ListMenuItems() { using (var context = new RestarauntContext()) { var data = from cat in context.MenuCategories orderby cat.Description select new CategoryDTO() //use the DTO { Description = cat.Description, MenuItems = from item in cat.Items where item.Active orderby item.Description select new MenuItemDTO // use the DTO { Description = item.Description, Price = item.CurrentPrice, Calories = item.Calories, Comment = item.Comment } }; return data.ToList(); //note: to use lambda or method style of include(), you need to have the following namespace reference: //use System.Data.Entity; //the Include() method on the Dbset<T> class peforms "eager loading" of the data. //return context.Items.Include(it => it.MenuCategory).ToList(); } }
public List<SpecialEvent> ListAllSpecialEvents() { //This using statement ensures that our connection to the database is properly "closed" once we are done "using" our DAL object using (RestarauntContext context = new RestarauntContext()) { return context.SpecialEvents.ToList(); } }
public List<MenuCategory> ListMenuCategories() { using(var context = new RestarauntContext()) { var data = from category in context.MenuCategories select category; return data.ToList(); } }
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 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 List<CategoryMenuItem> GetReportCategoryMenuItems() { using (var context = new RestarauntContext()) { var results = from cat in context.Items orderby cat.MenuCategory.Description, cat.Description select new CategoryMenuItem() { CategoryDescription = cat.MenuCategory.Description, ItemDescription = cat.Description, Price = cat.CurrentPrice, Calories = cat.Calories, Comment = cat.Comment }; return results.ToList(); } }
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(); } }