Beispiel #1
0
        public IActionResult OrderCreationForm(OrderCreateViewModel model)
        {
            if (model.Tables == null)
            {
                model.Tables = new List <Table>();
            }
            var usrID    = HttpContext.Session.GetInt32("userID");
            var waiterId = _context.Users.Where(w => w.UserId == (int)usrID).Include(e => e.Employee).ThenInclude(w => w.Waiter).FirstOrDefault().Employee.Waiter.WaiterId;
            var table    = _context.Tables.Find(model.CurrentTable);

            model.Tables.Add(table);
            var order = new Order {
                Duration = 0, ManagedByWaiterId = waiterId, OrderDate = DateTime.Now, State = (int)OrderState.Created, Price = 0.0
            };

            _context.Add(order);
            _context.SaveChanges();

            foreach (var t in model.Tables)
            {
                var to = new TableOccupancy {
                    OrderId = order.OrderId, TableId = t.TableNum
                };
                _context.Add(to);
            }
            _context.SaveChanges();
            return(RedirectToAction("OrderList"));
        }
        public void CreateOrderPriorityQueue(Reservation rev)
        {
            var order = new Order {
                OrderDate = DateTime.Now, Price = 0.0, Duration = 0, State = (int)OrderState.CreatedReservation
            };

            _context.Add(order);
            _context.SaveChanges();
            var tables = _context.Tables.ToList();
            var count  = rev.PeopleCount;
            var idList = new List <int>();
            var index  = 0;

            while (count > 0)
            {
                idList.Add(tables[index].TableNum);
                count = count - tables[index].SeatCount;
                index++;
            }
            foreach (int id in idList)
            {
                var temp = new TableOccupancy {
                    OrderId = order.OrderId, ReservationId = rev.ReservationId, TableId = id
                };
                _context.Add(temp);
            }
            _context.SaveChanges();
        }