public override void Execute()
        {
            TypedResult = new GetRandomUserResult();

            User[] users = new User[] {};

            var supplier = suppliersRepository.GetSupplierByName(SupplierName);

            if (supplier != null)
            {
                var order = orderRepository.GetActiveOrder(supplier);
                if (order == null)
                {
                    throw new AppException(ErrorCodes.Order.NoActiveOrder, supplier.Name);
                }

                TypedResult.Order = order;
                users             = order.Items.Select(i => i.User).Distinct().ToArray();
            }
            else
            {
                var today = DateTime.Now.Date;
                users = orderItemsRepository.AsQueryable()
                        .Where(u => u.Order.OrderDate == today)
                        .Select(i => i.User).Distinct().ToArray();
            }

            if (users.Any())
            {
                TypedResult.User  = randomizer.GetRandomItem(users);
                TypedResult.Users = users;
            }

            base.Execute();
        }
 private OrderItem GetLastOrderItem(string userName)
 {
     return(orderItemRepository.AsQueryable()
            .EagerFetch(i => i.Order)
            .EagerFetch(i => i.Order.Supplier)
            .EagerFetch(i => i.User)
            .Where(i => i.User.Name == userName)
            .Where(i => i.Order.OrderDate == DateTime.Today)
            .OrderByDescending(i => i.Id)
            .FirstOrDefault());
 }