コード例 #1
0
 // Konstruktor dla ViewModel-u typu RecipeSelect
 public RecipeDto(RecipeSelect select)
 {
     Id          = select.Id;
     Name        = select.Name;
     Price       = select.Price;
     Ingredients = select.Ingredients ?? new List <IngredientDto>();
 }
コード例 #2
0
        //private bool DishesCanBePrepared(IList<RecipeSelect> dishes, IReadOnlyDictionary<IngredientDto, int> ingredientsCountDictionary)
        //{
        //    foreach (var dish in dishes)
        //    {
        //        DishCanBePrepared(dish, ingredientsCountDictionary);
        //    }

        //    if (dishes.Count(d => !d.CanBePrepared) > 0)
        //    {
        //        return false;
        //    }

        //    return true;
        //}

        //How to do this?
        private bool DishCanBePrepared(RecipeSelect dish, IReadOnlyDictionary <IngredientDto, int> ingredientsCountDictionary, int amount)
        {
            dish.CanBePrepared = true;
            foreach (var ing in dish.Ingredients)
            {
                int value = 0;
                if (ingredientsCountDictionary.TryGetValue(ing, out value))
                {
                    if (value - amount >= 0)
                    {
                        continue;
                    }
                    //niewiadomo, czy properta bedzie potrzebna
                    dish.CanBePrepared = false;
                    return(false);
                }
                else
                {
                    //TODO: błąd!
                    //niewiadomo, czy properta bedzie potrzebna
                    dish.CanBePrepared = false;
                    return(false);
                }
            }

            return(true);
        }