Esempio n. 1
0
        /// <summary>
        /// (☞■ヮ■)☞
        /// </summary>
        /// <param name="basket"></param>
        public static void PerformReferendum(OrderBasket basket)
        {
            var orderOwners = basket.MatchedOrders.Select(o => o.CreatedBy).OrderBy(u => u.LastOrderDate);
            var basketCaptain = orderOwners.First();

            basket.Captain = basketCaptain; // (▀̿Ĺ̯▀̿ ̿)
        }
Esempio n. 2
0
 private void RestoreOrder(OrderBasket basket, ApplicationUser owner)
 {
     Order order = basket.PossibleOrders.Single(o => o.CreatedBy.Id == owner.Id);
     basket.PossibleOrders.Remove(order);
     basket.MatchedOrders.Add(order);
 }
Esempio n. 3
0
        private void ReduceBasketSize(OrderBasket orderBasket)
        {
            var reducedBasket = new OrderBasket() {RestaurantId = orderBasket.RestaurantId};

            Order[] orderListClone = new Order[orderBasket.MatchedOrders.Count];
            orderBasket.MatchedOrders.CopyTo(orderListClone);

            foreach (Order order in orderListClone)
            {
                // does owner of this order have other order in another basket?
                var orderOwner = order.CreatedBy;
                if (HasOrderInAnotherBasket(_orderBaskets, orderOwner, orderBasket.RestaurantId))
                {
                    // rewrite order to basket
                    orderBasket.MatchedOrders.Remove(order);
                    orderBasket.PossibleOrders.Add(order);
                }
            }

            // REVIEW: it's always false
            if (reducedBasket.MatchedOrders.Any())
            {
                _orderBaskets.Add(reducedBasket);
            }
        }
Esempio n. 4
0
        private void BalanceBasket(OrderBasket orderBasket)
        {
            Order[] orderListClone = new Order[orderBasket.MatchedOrders.Count];
            orderBasket.MatchedOrders.CopyTo(orderListClone);

            foreach (Order order in orderListClone)
            {
                // did this user have order in other, currently smaller basket?
                var orderOwner = order.CreatedBy;

                IEnumerable<Guid> currentlySmallerBaskets =
                    _orderBaskets.Where(b => (b.MatchedOrders.Count() < orderBasket.MatchedOrders.Count() || (b.MatchedOrders.Count() == orderBasket.MatchedOrders.Count() && orderBasket.RestaurantId != b.RestaurantId)))
                        .OrderByDescending(b => b.MatchedOrders.Count())
                        .Select(b => b.RestaurantId);

                OrderBasket smallerBasket =
                    _orderBaskets.FirstOrDefault(b => currentlySmallerBaskets.Contains(b.RestaurantId) &&
                                                      b.PossibleOrders.Any(o => o.CreatedBy.Id == orderOwner.Id));

                if (smallerBasket != null)
                {
                    // if so, remove order from this basket
                    orderBasket.MatchedOrders.Remove(order);
                    // while balancing DO NOT save order in PossibleOrders to avoid infinite loops

                    // and rewrite previously removed orders into smaller basket
                    RestoreOrder(smallerBasket, orderOwner);

                    CleanupEmptyBaskets();

                    break;
                }
            }
        }