示例#1
0
 public void test()
 {
     myShoopingListAdapter.GetItemsForShoppingList(Arg.Any <Guid>()).Returns(GetShoppingListItems());
     myProductAdapter.GetProductById(Arg.Any <Guid>()).Returns(myProduct);
     myShoopingListAdapter.GetInfoItemsForShoppingListItem(Arg.Any <Guid>()).Returns(GetInfoItems());
     var result = myService.GetShoppingListShopItems(Guid.NewGuid());
 }
示例#2
0
 public IEnumerable <BaseMeasurement> GetMeasurementsForProduct(Guid id)
 {
     return(myProductDataAdapter.GetProductById(id).ProductQuantities);
 }
示例#3
0
        public List <ShoppingListShopItem> GetShoppingListShopItems(Guid shoppingListId)
        {
            List <ShoppingListItemDetailsModel> items     = GetItemsForShoppingList(shoppingListId);
            List <ShoppingListShopItem>         shopItems = new List <ShoppingListShopItem>();
            var shoppingListITems = myShoppingListDataAdapter.GetItemsForShoppingList(shoppingListId);

            foreach (var item in items)
            {
                var totRequestedAmount = item.StaticAmount + (item.DynamicAmountRequested < item.DynamicAmountAvailable ? 0 : item.DynamicAmountRequested - item.DynamicAmountAvailable);
                if (totRequestedAmount == 0)
                {
                    continue;
                }
                var product = myProductDataAdapter.GetProductById(item.ProductId);

                var list = product.ProductQuantities.ToList();
                list.Sort(new ProductQuantitySorter());

                var quantitiesWithHigherAmount = list.Where(i => i.ConvertTo(item.MeasurementType) > totRequestedAmount);

                // if any with higher amount then required, we can add the lowest , which is the first
                if (quantitiesWithHigherAmount.Any() && false)
                {
                    var newShopItem = new ShoppingListShopItem
                    {
                        Id                     = item.Id,
                        ProductName            = item.ProductName,
                        Amount                 = 1,
                        Measurement            = quantitiesWithHigherAmount.First(),
                        IsChecked              = item.IsChecked, /// TODO,
                        ProductId              = item.ProductId,
                        MeasurementsForChecked = myShoppingListDataAdapter.GetMeasurementsForCheckedItem(item.Id)
                    };
                    shopItems.Add(newShopItem);
                    continue;
                }

                // TODO if not lowest
                var result = GetQuantityWithInfos(list, item.MeasurementType, totRequestedAmount);

                var resultZeroDiff = result.Where(r => r.DifferenceMin == 0);

                if (resultZeroDiff.Any())
                {
                    var minAmount = resultZeroDiff.Min(r => r.MaxPossibleForRequestMin);
                    var itemToUse = resultZeroDiff.First(r => r.MaxPossibleForRequestMin == minAmount);
                    shopItems.Add(new ShoppingListShopItem
                    {
                        Amount                 = Convert.ToInt32(itemToUse.MaxPossibleForRequestMin),
                        Measurement            = itemToUse.Measurement,
                        IsChecked              = item.IsChecked, /// TODO,
                        ProductId              = item.ProductId,
                        Id                     = item.Id,
                        ProductName            = item.ProductName,
                        MeasurementsForChecked = myShoppingListDataAdapter.GetMeasurementsForCheckedItem(item.Id)
                    });
                    continue;
                }

                result.OrderBy(r => r.DifferenceMax).ThenBy(s => s.MaxPossibleForRequestMax);

                shopItems.Add(new ShoppingListShopItem
                {
                    Amount                 = Convert.ToInt32(result.First().MaxPossibleForRequestMax),
                    Measurement            = result.First().Measurement,
                    IsChecked              = item.IsChecked, /// TODO,
                    ProductId              = item.ProductId,
                    Id                     = item.Id,
                    ProductName            = item.ProductName,
                    MeasurementsForChecked = myShoppingListDataAdapter.GetMeasurementsForCheckedItem(item.Id)
                });
            }


            return(shopItems);
        }
示例#4
0
        public IEnumerable <RecipeApiModel> GetAllRecipes()
        {
            var recipes = recipeAdapter.GetAllRecipes().Result.ToList();

            recipes.ForEach(r => r.IsAvailable = r.Ingredients.ToList().All(i => IsIngedientAvailable(i, productDataAdapter.GetProductById(i.ProductId))));
            return(recipes);
        }