示例#1
0
        public async Task <RegisterAndUpdateOutput> Create(SnackInput snackInput)
        {
            var snack = new Snack(snackInput.Name);

            foreach (var ingredient in snackInput.Ingredients)
            {
                var ingredientSnack = new Ingredient(ingredient.Name, ingredient.Price);
                ingredientSnack.AddQuantity(ingredient.Quantity);
                snack.AddIngredient(ingredientSnack);
            }

            await _snackRepository.Save(snack);

            await _snackRepository.UpdateSnackIngredients(snack);

            return(new RegisterAndUpdateOutput
            {
                Success = true,
                Message = "Snack registered with success.",
                Data = snack
            });
        }