Exemple #1
0
        /// <summary>
        /// Create order for a table
        /// </summary>
        /// <param name="tableNumber">Table Number</param>
        /// <param name="customerNote">Customer Note</param>
        /// <returns>Newly created order</returns>
        public Order CreateOrder(string tableNumber, string userID, string customerNote = "None")
        {
            var order = new Order
            {
                TableNumber  = tableNumber,
                Status       = OrderStatus.New,
                CustomerNote = customerNote,
                Price        = 0,
                UserID       = userID
            };

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

            return(_context.Orders.SingleOrDefault(o => o.ID == order.ID));
        }
Exemple #2
0
        /// <summary>
        /// Create receipt for an order
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>Newly created receipt</returns>
        public Receipt CreateReceipt(Order order, string userID, decimal tax)
        {
            var receipt = new Receipt
            {
                Order    = order,
                OrderID  = order.ID,
                Status   = ReceiptStatus.Pending,
                SubTotal = order.Price,
                Tax      = tax,
                UserID   = userID
            };

            receipt.Total = receipt.SubTotal * (1 + receipt.Tax / 100);

            _context.Receipts.Add(receipt);
            _context.SaveChanges();

            return(_context.Receipts.SingleOrDefault(r => r.ID == receipt.ID));
        }
        public Restaurant CreateRestaurant(string name, string address, string email, string phoneNumber, decimal tax, string userID)
        {
            if (tax < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            var restaurant = new Restaurant
            {
                Name         = name,
                Address      = address,
                EmailAddress = email,
                PhoneNumber  = phoneNumber,
                Tax          = tax,
                UserID       = userID
            };

            _context.Restaurant.Add(restaurant);
            _context.SaveChanges();
            return(_context.Restaurant.SingleOrDefault(r => r.ID == restaurant.ID));
        }
Exemple #4
0
        public Menu CreateMenu(string name, string userID)
        {
            if (userID == null)
            {
                throw new ArgumentNullException();
            }

            var menuIsExisted = _context.Menus.SingleOrDefault(m => m.UserID == userID && m.Name == name);

            if (menuIsExisted != null)
            {
                throw new ArgumentException();
            }

            var menu = new Menu
            {
                Name   = name,
                UserID = userID
            };

            _context.Menus.Add(menu);
            _context.SaveChanges();
            return(_context.Menus.SingleOrDefault(m => m.ID == menu.ID));
        }