当前位置: 首页>>代码示例>>C#>>正文


C# DAL.RestaurantContext类代码示例

本文整理汇总了C#中eRestaurant.DAL.RestaurantContext的典型用法代码示例。如果您正苦于以下问题:C# RestaurantContext类的具体用法?C# RestaurantContext怎么用?C# RestaurantContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RestaurantContext类属于eRestaurant.DAL命名空间,在下文中一共展示了RestaurantContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SplitBill

        public void SplitBill(int billId, List<OrderItem> updatesToOriginalBillItems, List<OrderItem> newBillItems)
        {
            // TODO: Actually go through and split that bill into two
            using (var context = new RestaurantContext())
            {
                // TODO: 0) Validation :)
                // 1) Get the bill
                var bill = context.Bills.Find(billId);
                if (bill == null) throw new ArgumentException("Invalid Bill ID - does not exist");

                // 2) Loop through bill items, if item not in original, remove
                List<BillItem> toMove = new List<BillItem>();
                foreach(var item in bill.Items) // the items already in the DB
                {
                    bool inOriginal = updatesToOriginalBillItems.Any(x => x.ItemName == item.Item.Description);
                    bool inNewItems = newBillItems.Any(x => x.ItemName == item.Item.Description);
                    if(!inOriginal)
                    {
                        // TODO: clean
                        if (!inNewItems)
                            throw new Exception("Hey - someone's got to pay for that!");
                        toMove.Add(item);
                    }
                }
                foreach (var item in toMove)
                    context.BillItems.Remove(item);

                // 3) Make a new bill
                var newBill = new Bill()
                {
                    BillDate = bill.BillDate,
                    Comment = "Split from bill# " + bill.BillID,
                    NumberInParty = bill.NumberInParty, // meh
                    OrderPlaced = bill.OrderPlaced,
                    OrderReady = bill.OrderReady,
                    OrderServed = bill.OrderServed,
                    WaiterID = bill.WaiterID
                    // TODO: thorny question about rules around splitting bill for a single table vs. reservation
                };

                // 4) Add the new missing items to the new bill
                foreach(var item in toMove)
                {
                    newBill.Items.Add(new BillItem()
                        {
                            ItemID = item.ItemID,
                            Notes = item.Notes,
                            Quantity = item.Quantity,
                            SalePrice = item.SalePrice,
                            UnitCost = item.UnitCost
                        });
                }

                // 5) Add the new bill to the context
                context.Bills.Add(newBill);

                // 6) hope for the best.
                context.SaveChanges();
            }
        }
开发者ID:Eirikson,项目名称:In-Class-A02,代码行数:60,代码来源:WaiterController.cs

示例2: ListSpecialEvents

 public List<SpecialEvent> ListSpecialEvents()
 {
     using (var context = new RestaurantContext())
     {
         return context.SpecialEvents.ToList();
     }
 }
开发者ID:mmayo2,项目名称:DMIT2018InClass,代码行数:7,代码来源:ReservationController.cs

示例3: ListMenuItems

 public List<Item> ListMenuItems()
 {
     using (var context = new RestaurantContext())
     {
         return context.Items.Include(it => it.MenuCategory).ToList();
     }
 }
开发者ID:mmayo2,项目名称:DMIT2018InClass,代码行数:7,代码来源:MenuController.cs

示例4: SeatCustomer

 /// <summary>
 /// Seats a customer that is a walk-in
 /// </summary>
 /// <param name="when">A mock value of the date/time (Temporary - see remarks)</param>
 /// <param name="tableNumber">Table number to be seated</param>
 /// <param name="customerCount">Number of customers being seated</param>
 /// <param name="waiterId">Id of waiter that is serving</param>
 public void SeatCustomer(DateTime when, byte tableNumber, int customerCount, int waiterId)
 {
     var availableSeats = AvailableSeatingByDateTime(when.Date, when.TimeOfDay);
     using (var context = new RestaurantContext())
     {
         List<string> errors = new List<string>();
         // Rule checking:
         // - Table must be available - typically a direct check on the table, but proxied based on the mocked time here
         // - Table must be big enough for the # of customers
         if (!availableSeats.Exists(x => x.Table == tableNumber))
             errors.Add("Table is currently not available");
         else if (!availableSeats.Exists(x => x.Table == tableNumber && x.Seating >= customerCount))
             errors.Add("Insufficient seating capacity for number of customers.");
         if (errors.Count > 0)
             throw new BusinessRuleException("Unable to seat customer", errors);
         Bill seatedCustomer = new Bill()
         {
             BillDate = when,
             NumberInParty = customerCount,
             WaiterID = waiterId,
             TableID = context.Tables.Single(x => x.TableNumber == tableNumber).TableID
         };
         context.Bills.Add(seatedCustomer);
         context.SaveChanges();
     }
 }
开发者ID:Eirikson,项目名称:In-Class-A02,代码行数:33,代码来源:SeatingController.cs

示例5: ListCategorizedMenuItems

        public List<Category> ListCategorizedMenuItems()
        {
            using (var context = new RestaurantContext())
            {
                var data = from cat in context.MenuCategories
                           orderby cat.Description
                           select new Category()
                           {
                               Description = cat.Description,
                               MenuItems = from item in cat.Items
                                           where item.Active
                                           orderby item.Description
                                           select new MenuItem()
                                           {
                                               Description = item.Description,
                                               Price = item.CurrentPrice,
                                               Calories = item.Calories,
                                               Comment = item.Comment
                                           }

                           };
                return data.ToList();
            }

        }
开发者ID:pjhas2,项目名称:DMIT-2018-In-class,代码行数:25,代码来源:MenuController.cs

示例6: ListAllWaiters

 public List<Waiter> ListAllWaiters()
 {
     using (RestaurantContext context = new RestaurantContext())
     {
         return context.Waiters.ToList();
     }
 }
开发者ID:Bbyrne6,项目名称:In-Class,代码行数:7,代码来源:RestaurantAdminController.cs

示例7: ReservationsByTime

 public List<ReservationCollection> ReservationsByTime(DateTime date)
 {
     using (var context = new RestaurantContext())
     {
         var result = from data in context.Reservations
                      where data.ReservationDate.Year == date.Year
                         && data.ReservationDate.Month == date.Month
                         && data.ReservationDate.Day == date.Day
                         && data.ReservationStatus == Reservation.Booked
                      select new ReservationSummary()
                      {
                          ID = data.ReservationID, // needed for when we actually seat the reservation
                          Name = data.CustomerName,
                          Date = data.ReservationDate,
                          NumberInParty = data.NumberInParty,
                          Status = data.ReservationStatus,
                          Event = data.SpecialEvent.Description,
                          Contact = data.ContactPhone
                          //,
                          //Tables = from seat in data.ReservationTables
                          //         select seat.Table.TableNumber
                      };
         var finalResult = from item in result
                           group item by item.Date.Hour into itemGroup
                           select new ReservationCollection()
                           {
                               Hour = itemGroup.Key,
                               Reservations = itemGroup.ToList()
                           };
         return finalResult.ToList();
     }
 }
开发者ID:punq,项目名称:DMIT2018inclass,代码行数:32,代码来源:SeatingController.cs

示例8: GetWaiter

 public Waiter GetWaiter(int waiterId)
 {
     using (RestaurantContext context = new RestaurantContext())
     {
         return context.Waiters.Find(waiterId);
     }
 }
开发者ID:Bbyrne6,项目名称:In-Class,代码行数:7,代码来源:RestaurantAdminController.cs

示例9: GetWaiter

 public Waiters GetWaiter(int WaiterID)
 {
     using(RestaurantContext context = new RestaurantContext())
     {
         return context.Waiters.Find(WaiterID);
     }
 }
开发者ID:tciarroni,项目名称:eRestaurant-Sample,代码行数:7,代码来源:RestaurantAdminController.cs

示例10: GetLastBillDateTime

 public DateTime GetLastBillDateTime()
 {
     using (var context = new RestaurantContext())
     {
         var result = context.Bills.Max(x => x.BillDate);
         return result;
     }
 }
开发者ID:mklause1,项目名称:DMIT2018-In-Class,代码行数:8,代码来源:AdHocController.cs

示例11: ListMenuItems

 public List<Item> ListMenuItems()
 {
     using(var context = new RestaurantContext())
     {   //Note: To use the lambda or Method style of Include, you need to use System.Data.Entity
         //get item data and include category data for each item
         //the .Include() method on the DbSet(T) class performs "eager loading" of data.
         return context.Items.Include(it => it.MenuCategory).ToList();
     }
 }
开发者ID:rsxlancer,项目名称:DMIT2018-In-Class,代码行数:9,代码来源:MenuController.cs

示例12: DeleteSpecialEvent

 public void DeleteSpecialEvent(SpecialEvent item)
 {
     using (RestaurantContext context = new RestaurantContext())
     {
         var existing = context.SpecialEvents.Find(item.EventCode);
         context.SpecialEvents.Remove(existing);
         context.SaveChanges();
     }
 }
开发者ID:Eirikson,项目名称:In-Class-A02,代码行数:9,代码来源:RestaurantAdminController.cs

示例13: DeleteItem

 public void DeleteItem(Item item)
 {
     using (RestaurantContext context = new RestaurantContext())
     {
         var existing = context.Items.Find(item.ItemID);
         context.Items.Remove(existing);
         context.SaveChanges();
     }
 }
开发者ID:Eirikson,项目名称:In-Class-A02,代码行数:9,代码来源:RestaurantAdminController.cs

示例14: AddSpecialEvent

 public void AddSpecialEvent(SpecialEvent item)
 {
     using (RestaurantContext context = new RestaurantContext())
     {
         // TODO: Validation rules...
         var added = context.SpecialEvents.Add(item);
         context.SaveChanges();
     }
 }
开发者ID:Eirikson,项目名称:In-Class-A02,代码行数:9,代码来源:RestaurantAdminController.cs

示例15: DeleteWaiter

 public void DeleteWaiter(Waiter item)
 {
     using (RestaurantContext context = new RestaurantContext())
     {
         var existing = context.Waiters.Find(item.WaiterID);
         context.Waiters.Remove(existing);
         context.SaveChanges();
     }
 }
开发者ID:Bbyrne6,项目名称:In-Class,代码行数:9,代码来源:RestaurantAdminController.cs


注:本文中的eRestaurant.DAL.RestaurantContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。