예제 #1
0
        public async Task CancelOrder(int id)
        {
            await StatusService.CheckRightsForOrderAddDelete();

            await ModifyOrder(id, new StatusModModel()
            {
                Status = nameof(OrderStatus.Cancelled)
            });
        }
예제 #2
0
        public async Task <AddResult> AddOrder(OrderAddModel model)
        {
            if (model.TableId == null && model.CustomerId == null)
            {
                throw new RestaurantBadRequestException("Asztal/kiszállítási adatok nélküli rendelés nem vehető fel!");
            }

            var waiter = await DbContext.Users.FindAsync(model.WaiterId);

            if (waiter == null)
            {
                throw new RestaurantNotFoundException("A megadott pincér nem létezik!");
            }

            await StatusService.CheckRightsForOrderAddDelete();

            OrderSession orderSession = null;

            if (model.TableId != null)
            {
                orderSession = await DbContext.OrderSessions.Where(os => os.TableId == model.TableId && os.Status == OrderSessionStatus.Active).SingleOrDefaultAsync();
            }

            if (orderSession == null)
            {
                orderSession = await OrderSessionService.CreateNewSession(model);
            }

            var order = DbContext.Orders.Add(new Order()
            {
                WaiterUserId   = model.WaiterId,
                Status         = OrderStatus.Ordering,
                OrderSessionId = orderSession.Id,
                OpenedAt       = DateTime.Now
            });

            await DbContext.SaveChangesAsync();

            return(new AddResult(order.Entity.Id));
        }