public RestaurantOrder Show()
        {
            Console.Clear();
            Console.WriteLine("Servitörens namn:");
            string namn = Console.ReadLine();

            Console.WriteLine("Bord nummer:");
            int tableNo = Convert.ToInt32(Console.ReadLine());
            var order   = new RestaurantOrder
            {
                TableNumber = tableNo,
                Servant     = namn,
                OrderStatus = RestaurantOrder.Status.Received,
                OrderParts  = new List <RestaurantOrderRow>()
            };

            while (true)
            {
                Console.WriteLine("Produkt att lägga till (ex hamburgertallrik):");
                string prod = Console.ReadLine();
                Console.WriteLine("Antal");
                int count = Convert.ToInt32(Console.ReadLine());
                order.OrderParts.Add(new RestaurantOrderRow {
                    Count = count, Product = prod
                });
                Console.WriteLine("Lägga till fler J/N?");
                if (Console.ReadLine().ToLower() != "j")
                {
                    break;
                }
            }
            return(order);
        }
Beispiel #2
0
        // PUT api/RestaurantOrder/5
        public IHttpActionResult PutRestaurantOrder(RestaurantOrder restaurantorder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //if (id != restaurantorder.RestaurantOrderId)
            //{
            //    return BadRequest();
            //}

            restaurantorder.UpdatedDate     = DateTime.Now;
            db.Entry(restaurantorder).State = System.Data.Entity.EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantOrderExists(restaurantorder.RestaurantOrderId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
 public static OrderDTO Convert(RestaurantOrder obj)
 {
     return(new OrderDTO
     {
         EmployeeID = obj.EmployeeId,
         OrderDate = obj.OrderDate,
         OrderNo = obj.OrderNo,
         PaymentCondition = obj.PaymentCondition.Condition,
         ReservationID = obj.Reservation.Id,
         OrderLines = Convert(obj.OrderLine)
     });
 }
Beispiel #4
0
        public OrderDTO Create(OrderDTO obj, bool transactionEndpoint = true)
        {
            //Sanity check here, ensure unique tables etc
            if (transactionEndpoint)
            {
                _context.Database.BeginTransaction(IsolationLevel.Serializable);
            }
            try
            {
                if (RestaurantOrder.Validate(obj))
                {
                    RestaurantOrder order       = null;
                    var             notNewOrder = _context.RestaurantOrder.FirstOrDefault(o => o.ReservationId == obj.ReservationID);
                    if (notNewOrder != null)
                    {
                        var orderDto = Update(obj, false);
                        order = Converter.Convert(orderDto);
                    }
                    else
                    {
                        order             = Converter.Convert(obj);
                        order.OrderDate   = DateTime.Now;
                        order.Employee    = _context.Employee.FirstOrDefault(e => e.Id.Equals(obj.EmployeeID));
                        order.Reservation = _context.Reservation.FirstOrDefault(r => r.Id.Equals(obj.ReservationID));
                        var tempPaymentCondition = _context.PaymentCondition.FirstOrDefault(x => x.Condition.Equals(obj.PaymentCondition)).Id;
                        if (tempPaymentCondition > 0)
                        {
                            order.PaymentConditionId = tempPaymentCondition;
                            order.PaymentCondition   =
                                _context.PaymentCondition.FirstOrDefault(pc => pc.Id.Equals(order.PaymentConditionId));
                        }

                        var added = _context.RestaurantOrder.Add(order);
                        _context.SaveChanges();
                    }


                    if (transactionEndpoint)
                    {
                        _context.Database.CommitTransaction();
                    }
                    _context.Entry(order).GetDatabaseValues();
                    return(GetById(order.OrderNo));
                }
            }
            catch (Exception)
            {
                _context.Database.RollbackTransaction();
                throw;
            }

            return(null);
        }
Beispiel #5
0
        public void ProcessClientRequests()
        {
            foreach (var client in this.clients)
            {
                var waiter = this.waiters.FirstOrDefault(x => x.IsAvailable);
                if (waiter == null)
                {
                    throw new KeyNotFoundException("No waiters available");
                }

                // TODO: Extract the order generation in the client or in a DataGenerator class
                var order = new RestaurantOrder
                {
                    Beverages = new Collection <IBeverage>
                    {
                        new Beverage
                        {
                            PortionSizeInMilliliters = 250,
                            TotalPrice = 10,
                            Type       = BeverageType.Beer
                        },
                        new Beverage
                        {
                            PortionSizeInMilliliters = 300,
                            TotalPrice = 2,
                            Type       = BeverageType.WellWater
                        }
                    },
                    Foods = new Collection <IFood> {
                        new Food
                        {
                            PortionSizeInGrams = 500,
                            TotalPrice         = 3,
                            Type = FoodType.FruitSalad
                        },
                        new Food
                        {
                            PortionSizeInGrams = 450,
                            TotalPrice         = 5,
                            Type = FoodType.VegetablesSalad
                        }
                    }
                };

                waiter.GetOrder(order, client);
                waiter.ServeOrder(client);
                waiter.RequestPayment(client);
            }
        }
Beispiel #6
0
        //Denne her er kun til at update PaymentCondition og employee, indtil videre
        //TODO add so it handles change in food (update food).
        public OrderDTO Update(OrderDTO obj, bool transactionEndpoint = true)
        {
            if (!RestaurantOrder.Validate(obj))
            {
                throw new ValidationException("Bad input");
            }
            if (transactionEndpoint)
            {
                _context.Database.BeginTransaction(IsolationLevel.Serializable);
            }
            try
            {
                var tempOrder = Converter.Convert(obj);

                var order = _context.RestaurantOrder
                            .Where(o => o.OrderNo == obj.OrderNo)
                            .Include(f => f.OrderLine)
                            .ThenInclude(f => f.Food)
                            .ThenInclude(f => f.Price)
                            .Include(f => f.OrderLine)
                            .ThenInclude(f => f.Food.FoodCategory)
                            .Include(e => e.Employee)
                            .ThenInclude(e => e.Person)
                            .ThenInclude(e => e.Location)
                            .ThenInclude(e => e.ZipCodeNavigation)
                            .Include(e => e.Employee.Title)
                            .Include(r => r.Reservation)
                            .Include(pc => pc.PaymentCondition).OrderBy(x => x.OrderDate).FirstOrDefault();

                order.EmployeeId = tempOrder.EmployeeId;

                order.PaymentConditionId = tempOrder.PaymentConditionId;
                _context.Update(order);

                if (transactionEndpoint)
                {
                    _context.SaveChanges();
                    _context.Database.CommitTransaction();
                    return(GetById(order.OrderNo));
                }
            }
            catch (Exception)
            {
                _context.Database.RollbackTransaction();
                throw;
            }

            return(null);
        }
Beispiel #7
0
        public IHttpActionResult GetRestaurantOrder(int id)
        {
            RestaurantOrder restaurantorder = db.RestaurantOrders.Find(id);

            if (restaurantorder == null)
            {
                return(NotFound());
            }

            Login login = db.Logins.Find(restaurantorder.LoginId);

            restaurantorder.Login = login;

            return(Ok(restaurantorder));
        }
        public bool Add(RestaurantOrderApiModel restaurantOrdermodel)
        {
            order = new RestaurantOrder
            {
                EmployeeID = restaurantOrdermodel.EmployeeID,
                CustomerID = restaurantOrdermodel.CustomerID,
                OrderID    = restaurantOrdermodel.OrderID,
                OrderDate  = restaurantOrdermodel.OrderDate,
                OrderType  = restaurantOrdermodel.OrderType,
                ReataurantOrderDetailModel = restaurantOrdermodel.ReataurantOrderDetail,
                Qty         = restaurantOrdermodel.Qty,
                ItemId      = restaurantOrdermodel.ItemId,
                OrderTypeID = restaurantOrdermodel.OrderTypeID
            };

            return(restaurantOrder.RecordRestaurantOrder(order));
        }
        // GET api/RestaurantOrderItems
        public IQueryable <RestaurantOrderItem> GetRestaurantOrderItems()
        {
            var items = db.RestaurantOrderItems;

            foreach (var item in items)
            {
                FoodItem foodItem = db.FoodItems.Find(item.FoodItemId);
                item.FoodItem = foodItem;

                RestaurantOrder restaurantOrder = db.RestaurantOrders.Find(item.RestaurantOrderId);
                Restaurateur    restaurateur    = db.Restaurateurs.Find(restaurantOrder.RestaurateurId);
                restaurantOrder.Restaurateur = restaurateur;
                item.RestaurantOrder         = restaurantOrder;
            }

            return(db.RestaurantOrderItems.OrderBy(a => (a.RestaurantOrderItemsId)));
        }
Beispiel #10
0
        public IHttpActionResult PostRestaurantOrder(RestaurantOrder restaurantorder)
        {
            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}

            restaurantorder.PaymentStatusId = 2; //Pending
            restaurantorder.OrderStatusId   = 1; //Order Received
            restaurantorder.OrderDate       = DateTime.Now.ToString();
            restaurantorder.CreatedDate     = DateTime.Now;
            restaurantorder.IsDeleted       = false;
            db.RestaurantOrders.Add(restaurantorder);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = restaurantorder.RestaurantOrderId }, restaurantorder));
        }
Beispiel #11
0
        public IHttpActionResult UpdateRestaurantOrderResponse(int RestaurantOrderId, string TrackingId, string BankRefNo, string OrderStatus)
        {
            RestaurantOrder restaurantOrder = db.RestaurantOrders.Find(RestaurantOrderId);

            if (restaurantOrder == null)
            {
                return(NotFound());
            }

            restaurantOrder.TrackingId      = TrackingId;
            restaurantOrder.BankRefNo       = BankRefNo;
            restaurantOrder.OrderStatus     = OrderStatus;
            db.Entry(restaurantOrder).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(Ok(restaurantOrder));
        }
Beispiel #12
0
        public IHttpActionResult DeleteRestaurantOrder(int id, int loginId)
        {
            RestaurantOrder restaurantorder = db.RestaurantOrders.Find(id);

            if (restaurantorder == null)
            {
                return(NotFound());
            }


            restaurantorder.UpdatedBy       = loginId;
            restaurantorder.UpdatedDate     = DateTime.Now;
            restaurantorder.IsDeleted       = true;
            db.Entry(restaurantorder).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(Ok(restaurantorder));
        }
 public String Post(RestaurantOrder order)
 {
     return("Order saved.");
 }
Beispiel #14
0
        public void ProcessClientRequests()
        {
            foreach(var client in this.clients)
            {
                var waiter = this.waiters.FirstOrDefault(x => x.IsAvailable);
                if(waiter == null)
                {
                    throw new KeyNotFoundException("No waiters available");
                }

                // TODO: Extract the order generation in the client or in a DataGenerator class
                var order = new RestaurantOrder
                {
                    Beverages = new Collection<IBeverage>
                    {
                        new Beverage
                        {
                            PortionSizeInMilliliters = 250,
                            TotalPrice = 10,
                            Type = BeverageType.Beer
                        },
                        new Beverage
                        {
                            PortionSizeInMilliliters = 300,
                            TotalPrice = 2,
                            Type = BeverageType.WellWater
                        }
                    },
                    Foods = new Collection<IFood> {
                        new Food
                        {
                            PortionSizeInGrams = 500,
                            TotalPrice = 3,
                            Type = FoodType.FruitSalad
                        },
                        new Food
                        {
                            PortionSizeInGrams = 450,
                            TotalPrice = 5,
                            Type = FoodType.VegetablesSalad
                        }
                    }
                };

                waiter.GetOrder(order, client);
                waiter.ServeOrder(client);
                waiter.RequestPayment(client);
            }
        }