Esempio n. 1
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;
            db.orders.Add(order);
            foreach (var item in shoppinCartRepo.ViewShoppingCart())
            {
                DrinkOrder drinkOrder = new DrinkOrder
                {
                    DrinkId = item.Drink.DrinkId,
                    OrderId = order.OrderId,
                    Amount  = item.amount,
                    Price   = item.Drink.Price * item.amount
                };
                db.drinkOrders.Add(drinkOrder);
            }

            if (db.SaveChanges() < 0)
            {
                foreach (var item in shoppinCartRepo.ViewShoppingCart())
                {
                    item.Drink.Stock += item.amount;
                }
                db.SaveChanges();
            }
        }
Esempio n. 2
0
        public void CommandModeTest()
        {
            Console.WriteLine("======== 命令模式測試 =========");

            //開店準備
            Chef      chef       = new Chef();
            Bartender bartender  = new Bartender();
            Order     dishOrder  = new DishOrder(chef);
            Order     drinkOrder = new DrinkOrder(bartender);
            Waitress  cuteGirl   = new Waitress();

            //開始營業 客戶點餐
            cuteGirl.SetOrder(dishOrder);
            cuteGirl.SetOrder(dishOrder);
            cuteGirl.SetOrder(drinkOrder);
            cuteGirl.SetOrder(drinkOrder);

            //飲料還沒賣完
            cuteGirl.SetOrder(drinkOrder);

            Console.WriteLine("===== 客人取消熱炒測試 =====");
            //取消一份熱炒
            cuteGirl.CancelOrder(dishOrder);
            //熱炒又可以賣了
            cuteGirl.SetOrder(dishOrder);

            Console.WriteLine("=== 點餐完成 通知廚房 ===");
            cuteGirl.NotifyKitchen();

            Console.WriteLine("=== 熱炒庫存不足測試 ===");
            cuteGirl.SetOrder(dishOrder);

            Assert.AreEqual(1, 1);
        }
Esempio n. 3
0
        public ActionResult SaveOrder(OrderIndexVM orderIndexVM)
        {
            //saves to the table
            var order = new Order
            {
                CustomerID = orderIndexVM.CustomerID,
                LocationID = orderIndexVM.LocationID,
                Total      = GetTotal(orderIndexVM.DrinkOrders)
            };

            order = _orderBL.AddOrder(order);
            foreach (var item in orderIndexVM.DrinkOrders)
            {
                if (item.Quantity > 0)
                {
                    var drinkOrder = new DrinkOrder
                    {
                        DrinkId  = item.DrinkId,
                        OrderId  = order.OrderID,
                        Quantity = item.Quantity
                    };
                    _orderBL.AddDrinkOrder(drinkOrder);
                }
                var inventory = _inventoryBL.GetInventoryByLocationIDAndDrinkID(order.LocationID, item.DrinkId);
                if (inventory != null)
                {
                    inventory.Quantity -= item.Quantity;
                    _inventoryBL.UpdateInventory(inventory);
                }
            }



            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 4
0
 public bool EditDrinkOrder(DrinkOrder order)
 {
     using (SqlConnection conn = new SqlConnection(_connectionString))
     {
         var sql = @"UPDATE DrinkOrder SET
                         Comment = @Comment,
                         DrinkId = @DrinkId,
                         OrderId = @OrderId,
                         Quantity = @Quantity
                     WHERE
                         DrinkOrderId = @DrinkOrderId";
         try
         {
             conn.Execute(sql, new {
                 @Comment      = order.Comment,
                 @DrinkId      = order.DrinkId,
                 @OrderId      = order.OrderId,
                 @Quantity     = order.Quantity,
                 @DrinkOrderId = order.DrinkOrderId
             });
         }
         catch (Exception)
         {
             return(false);
         }
     }
     return(true);
 }
        public void Post_To_Empty_List_Successfully_Adds_Item()
        {
            //Arrange
            DbContextOptions <ShoppingListContext> options = new TestHelper().GetShoppingListContextOptions();

            var expectedObject = new DrinkOrder
            {
                Name     = "Pepsi",
                Quantity = 1
            };

            var expectedResult = new CreatedResult("", expectedObject);

            using (var context = new ShoppingListContext(options))
            {
                IShoppingListRepository mockRepo = new ShoppingListRepository(context);

                var controller = new ShoppingListController(mockRepo);
                controller.ControllerContext             = new ControllerContext();
                controller.ControllerContext.HttpContext = new DefaultHttpContext();

                //Act
                var result = controller.Post(expectedObject) as CreatedResult;

                //Assert
                Assert.IsNotNull(result);
                Assert.AreEqual(201, result.StatusCode);
                //Can't effectively mock HttpRequest, and don't really want to go down that rabbit hole so just check
                //it's not null.
                Assert.IsNotNull(result.Location);
                Assert.AreEqual(result.Value, expectedResult.Value);
            }
        }
Esempio n. 6
0
    // adds customer to this seat
    public void addCustomer(GameObject newCustomer, DrinkOrder order, Transform location)
    {
        // make sure we don't already have a customer
        if (customer != null)
        {
            return;
        }

        arrived       = false;
        customerOrder = order;

        // get location of customer for this seat
        Transform customerPlacement = this.gameObject.transform.GetChild(1).transform;

        customer = (GameObject)Instantiate(newCustomer, location.position, Quaternion.identity);
        customer.transform.position += new Vector3(3f, 3f, 3f);
        customer.GetComponent <MoveAgent>().spawnLocation = location;

        // disable billboard while customer is walking
        customer.transform.Find("NewCustomerOrderUI").gameObject.SetActive(false);

        // hide text that shows added score
        customer.transform.GetChild(1).GetComponent <TextMesh>().text = "";

        // set customer's destination to this seat
        customer.GetComponent <MoveAgent>().SetDestination(customerPlacement.position);
    }
Esempio n. 7
0
        public static void Run()
        {
            // Builder Pattern
            //  - a director object which enforces a specific process uses builders
            //  - these builders implement the builder abstraction that the director depends on
            //  - these builders enable variations in details of each step in the process enforced by the director

            var coffeeMaker = new CoffeeMaker();

            var americano     = new AmericanoBuilder();
            var latte         = new LatteBuilder();
            var flavoredlatte = new FlavoredLatteBuilder();

            var ventiIcedAmericanoOrder     = new DrinkOrder(iced: true, DrinkSize.Venti, americano);
            var tallIcedLatteOrder          = new DrinkOrder(iced: true, DrinkSize.Tall, latte);
            var grandeHotFlavoredLatteOrder = new DrinkOrder(iced: false, DrinkSize.Grande, flavoredlatte);

            coffeeMaker.AcceptOrder(ventiIcedAmericanoOrder);
            coffeeMaker.BuildCoffee();
            var ventiIcedAmericano = coffeeMaker.GetCoffee();

            Console.WriteLine(ventiIcedAmericano.Description);

            coffeeMaker.AcceptOrder(tallIcedLatteOrder);
            coffeeMaker.BuildCoffee();
            var tallIcedLatte = coffeeMaker.GetCoffee();

            Console.WriteLine(tallIcedLatte.Description);

            coffeeMaker.AcceptOrder(grandeHotFlavoredLatteOrder);
            coffeeMaker.BuildCoffee();
            var grandeHotFlavoredLatte = coffeeMaker.GetCoffee();

            Console.WriteLine(grandeHotFlavoredLatte.Description);
        }
Esempio n. 8
0
        public void AcceptOrder(DrinkOrder drinkOrder)
        {
            _coffeeBuilder = drinkOrder.Drink;

            _coffeeBuilder.StartCoffee(drinkOrder.DrinkSize, drinkOrder.Iced);
            _coffeeBuilder.MapSizeToShots();
            _coffeeBuilder.MapSizeToPumps();
        }
Esempio n. 9
0
        public DrinkOrder Update(DrinkOrder update)
        {
            var drink = _appDbContext.DrinkOrders.Attach(update);

            drink.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _appDbContext.SaveChanges();
            return(update);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            DrinkOrder drinkOrder = db.DrinkOrders.Find(id);

            db.DrinkOrders.Remove(drinkOrder);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 11
0
 public void AddDrinkOrder()
 {
     LogFns.DebugWriteLine("Adding new DrinkOrder: " + DrinkName);
     var drinkOrder = new DrinkOrder {DrinkName = DrinkName};
     DrinkOrders.Add(drinkOrder);
     SelectedDrinkOrder = drinkOrder;
     ReadyForNewDrink();
 }
Esempio n. 12
0
        public void AddDrinkOrder()
        {
            var drink = new DrinkOrder {
                DrinkName = DrinkName
            };

            DrinkOrders.Add(drink);
            SelectedDrinkOrder = drink;
        }
 public ActionResult Edit([Bind(Include = "OrderId,Completed,CustomerName,Alcohol,Mixer")] DrinkOrder drinkOrder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(drinkOrder).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(drinkOrder));
 }
        public ObjectResult Put([FromBody] DrinkOrder drinkOrder)
        {
            var result = _shoppingListRepository.Update(drinkOrder);

            if (result == null)
            {
                return(new NotFoundObjectResult($"Drink: {drinkOrder.Name} not found on the shopping list."));
            }

            return(new OkObjectResult(result));
        }
        public ActionResult Create([Bind(Include = "OrderId,Completed,CustomerName,Alcohol,Mixer")] DrinkOrder drinkOrder)
        {
            if (ModelState.IsValid)
            {
                db.DrinkOrders.Add(drinkOrder);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(drinkOrder));
        }
        public void GetDrinkCode_Should_Call_GetCode_Of_Drink()
        {
            // GIVEN
            var         drink      = Substitute.For <IDrink>();
            IDrinkOrder drinkOrder = new DrinkOrder(drink);

            // WHEN
            drinkOrder.GetDrinkCode();

            // THEN
            drink.Received().GetCode();
        }
        /// <summary>
        /// If entity already exists, return nothing. Otherwise return the inserted entity.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public DrinkOrder Insert(DrinkOrder entity)
        {
            DrinkOrder drinkOrder = _context.shoppingList.AsNoTracking().FirstOrDefault(x => x.Name == entity.Name);

            if (drinkOrder != null)
            {
                return(null);
            }
            _context.shoppingList.Add(entity);
            _context.SaveChanges();
            return(entity);
        }
Esempio n. 18
0
        public static GameAction OrderDrinkWithoutFailure(Entity entity, DrinkOrder drinkOrder, Conversation conversation, int orderTimeoutInMins = 20)
        {
            var orderDrink = new ParallelUntilAllCompleteAction("OrderDrink");

            orderDrink.Add(new ReportSuccessDecorator(new ConversationAction(conversation)));
            var waitForDrink = new ConditionalActionSequence("WaitForDrink");

            waitForDrink.Add(new StartDrinkOrderAction(drinkOrder));
            waitForDrink.Add(CommonActions.WaitForDrinkWithoutFailure(entity, drinkOrder, orderTimeoutInMins));
            orderDrink.Add(waitForDrink);
            return(orderDrink);
        }
Esempio n. 19
0
    public void FillPanel(DrinkOrder order)
    {
        var drink = order.Drink;

        drinkImage.sprite = drink.drinkSprite;
        var orbSprites = GetOrbSprites(drink);

        for (int i = 0; i < orbImages.Length; i++)
        {
            orbImages[i].sprite = orbSprites[i];
        }
        text.text = drink.drinkPrice.ToString("C2");
    }
Esempio n. 20
0
        public void GetDrinkCode_Should_Return_Sugar_Qty_From_Drink(int expectedSugarQty)
        {
            // arange
            var drink = new Mock <IHotDrink>();

            drink.Setup(x => x.SugarQty).Returns(expectedSugarQty);

            // act
            var DrinkOrder = new DrinkOrder(drink.Object);

            // assert
            Assert.Equal(expectedSugarQty, DrinkOrder.GetDrinkSugarQty());
        }
Esempio n. 21
0
        public void GetDrinkCode_Should_Return_Code_From_Drink(string expectedDrinkCode)
        {
            // arange
            var drink = new Mock <IDrink>();

            drink.SetupGet(x => x.Code).Returns(expectedDrinkCode);

            // act
            var DrinkOrder = new DrinkOrder(drink.Object);

            // assert
            Assert.Equal(expectedDrinkCode, DrinkOrder.GetDrinkCode());
        }
        // GET: DrinkOrders/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DrinkOrder drinkOrder = db.DrinkOrders.Find(id);

            if (drinkOrder == null)
            {
                return(HttpNotFound());
            }
            return(View(drinkOrder));
        }
Esempio n. 23
0
        public void AddCommand_should_Add_Order_ToReport()
        {
            // arrange
            IRepository repo       = new Repository();
            IDrink      coffee     = new Coffee();
            IDrinkOrder drinkOrder = new DrinkOrder(coffee);

            // act
            repo.AddCommand(drinkOrder, DateTime.Now);
            var Report = repo.GetReport();

            // assert
            Assert.NotEmpty(Report);
        }
Esempio n. 24
0
        public static ActionSequence OrderDrink(Entity entity, DrinkOrder drinkOrder, Conversation conversation, Conversation correctDrinkConversation = null, Conversation incorrectDrinkConversation = null, Dictionary <String, GameAction> otherDrinkActions = null, int orderTimeoutInMins = 40)
        {
            var wrapper    = new ActionSequence("DrinkOrderThenClear");
            var orderDrink = new ParallelUntilAllCompleteAction("OrderDrink");

            orderDrink.Add(new ReportSuccessDecorator(new ConversationAction(conversation)));
            var waitForDrink = new ConditionalActionSequence("WaitForDrink");

            waitForDrink.Add(new StartDrinkOrderAction(drinkOrder));
            waitForDrink.Add(CommonActions.WaitForDrink(entity, drinkOrder.OrderedItem, drinkOrder, orderTimeoutInMins, correctDrinkConversation: correctDrinkConversation, incorrectDrinkConversation: incorrectDrinkConversation, otherDrinkActions: otherDrinkActions));
            orderDrink.Add(waitForDrink);
            wrapper.Add(orderDrink);
            wrapper.Add(new ClearConversationAction());
            return(wrapper);
        }
        public void GetDrinkCode_Should_Return_Code_From_Drink(string expectedDrinkCode)
        {
            // GIVEN
            var drink = Substitute.For <IDrink>();

            drink.GetCode().Returns(expectedDrinkCode);

            IDrinkOrder drinkOrder = new DrinkOrder(drink);

            // WHEN
            var drinkCode = drinkOrder.GetDrinkCode();

            // THEN
            Check.That(drinkCode).IsEqualTo(expectedDrinkCode);
        }
        public void GetSugarQuantity_Return_Sugar_Quantity_Of_HotDrink(int expectedSugarQuantity)
        {
            // GIVEN
            var drink = Substitute.For <IHotDrink>();

            drink.GetSugarQuantity().Returns(expectedSugarQuantity);

            IDrinkOrder drinkOrder = new DrinkOrder(drink);

            // WHEN
            int sugarQuantity = drinkOrder.GetSugarQuantity();

            // THEN
            Check.That(sugarQuantity).IsEqualTo(expectedSugarQuantity);
        }
        public void GetPrice_Should_Return_Price_Of_Drink(double expectedPrice)
        {
            // GIVEN
            IDrink drink = Substitute.For <IDrink>();

            drink.GetPrice().Returns(expectedPrice);

            IDrinkOrder drinkOrder = new DrinkOrder(drink);

            // WHEN
            double orderPrice = drinkOrder.GetPrice();

            // THEN
            Check.That(orderPrice).IsEqualTo(expectedPrice);
        }
Esempio n. 28
0
        public IActionResult RemoveDrink(int id)
        {
            DrinkOrder order = data.DrinkOrders.Find(id);

            order.Active = false;
            data.Update(order);
            data.SaveChanges();
            IEnumerable <DrinkOrder> orders = data.DrinkOrders.Where(o => o.Active == true);

            foreach (DrinkOrder drink in orders)
            {
                drink.OrderedDrink  = data.Drinks.Find(drink.DrinkId);
                drink.Customization = data.Customizations.Find(drink.CustomizationId);
            }
            return(View("GetOrders", orders));
        }
        public ObjectResult Post([FromBody] DrinkOrder drinkOrder)
        {
            var result = _shoppingListRepository.Insert(drinkOrder);

            if (result == null)
            {
                var objectResult = new ObjectResult(Json($"Drink {drinkOrder.Name} already exists in the shopping list."));
                objectResult.StatusCode = (int)HttpStatusCode.Conflict;
                return(objectResult);
            }

            string returnedUri = string.Format("{0}://{1}{2}/{3}",
                                               this.HttpContext.Request.Scheme, this.HttpContext.Request.Host, this.Request.Path, drinkOrder.Name);

            return(Created(returnedUri, drinkOrder));
        }
Esempio n. 30
0
        public void AddDrinkOrder()
        {
            if (!CanAddDrinkOrder)
            {
                return;                    // for safety
            }
            if (DrinkOrders.Count == 10)
            {
                DrinkOrders.Clear(); // Reset at 10 drinks of any kind
            }
            var drink = new DrinkOrder(SelectedBeverage);

            DrinkOrders.Add(drink);
            SelectedDrinkOrder = drink;
            SetInebriationState();
            ReadyForNewDrink();
        }
Esempio n. 31
0
        public void AddCommand_should_Have_All_OrderDrink(int expectedLength)
        {
            // arrange
            IRepository repo        = new Repository();
            IDrink      coffee      = new Coffee();
            IDrinkOrder drinkOrder1 = new DrinkOrder(coffee);
            IDrink      Orange      = new Coffee();
            IDrinkOrder drinkOrder2 = new DrinkOrder(coffee);

            // act
            repo.AddCommand(drinkOrder1, DateTime.Now);
            repo.AddCommand(drinkOrder2, DateTime.Now);
            var Report = repo.GetReport();

            // assert
            Assert.Equal(expectedLength, Report.Count);
        }