public async Task <RegisterAndUpdateOutput> Update(SnackInput snackInput) { var snack = await _snackRepository.GetById(snackInput.Id); if (snack == null) { return(null); } snack.update(snack.Name); foreach (var ingredient in snackInput.Ingredients) { var ingredientSnack = new Ingredient(ingredient.Name, ingredient.Price); ingredientSnack.AddQuantity(ingredient.Quantity); snack.AddIngredient(ingredientSnack); } await _snackRepository.Update(snack); await _snackRepository.UpdateSnackIngredients(snack); return(new RegisterAndUpdateOutput { Success = true, Message = "Snack updated with success.", Data = snack }); }