public void PlaceOrder(Guid customerId, IEnumerable <OrderItem> orderItems)
        {
            var customer      = _customerRepository.Get(customerId);
            var customerOrder = new CustomerOrder(customer);

            // Hack: There is an issue with EF Core not properly processing the join statement.
            var itemIds = orderItems.Select(i => i.ItemId).Distinct();
            var items   = _itemRepository.Items
                          .Where(i => itemIds.Contains(i.Id))
                          //.Join(orderItems,
                          //      item => item.Id,
                          //      orderedItem => orderedItem.ItemId,
                          //      (item, _) => item)
                          .ToDictionary(i => i.Id);

            foreach (var orderedItem in orderItems)
            {
                var item = items[orderedItem.ItemId];
                item.DecreaseStockCount(orderedItem.Quantity);
                _itemRepository.Update(item);
                customerOrder.Add(orderedItem);
            }

            _customerOrderRepository.Register(customerOrder);
            _unitOfWork.Commit();
        }
Exemple #2
0
        public void PlaceOrder(Guid customerId, IEnumerable <OrderItem> orderItems)
        {
            var customer = _customerRepository.Get(customerId);
            var order    = new CustomerOrder(customer);

            foreach (var orderedItem in orderItems)
            {
                var item = _itemRepository.Get(orderedItem.ItemId);
                item.DecreaseStockCount(orderedItem.Quantity);
                _itemRepository.Update(item);
                order.Add(orderedItem);
            }

            _customerOrderRepository.Register(order);
            _unitOfWork.Commit();
        }
    /// <summary>
    /// Method called for the customer to place his order
    /// </summary>
    private void SelectOrder()
    {
        // Add the first required ingredient (likely chopped lettuce)
        CustomerOrder.Add(requiredIngredient);
        // Select additional random ingredient count (determined by the min / max ingredient order values)
        int ingredientOrderCount = Random.Range(minIngredientsOnOrder, maxIngredientsOnOrder + 1);

        // While the customer order ingredients is less than the required amount,
        // keep adding random ingredients into the recipe order
        while (CustomerOrder.Count < ingredientOrderCount)
        {
            Ingredient randomIngredient = additionalSaladIngredients[Random.Range(0, additionalSaladIngredients.Count)];
            CustomerOrder.Add(randomIngredient);
        }
        // Initialize the timers on this customer's order
        InitializeTimers();

        OnCustomerOrderPlaced.Invoke(this);
    }