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 }); }
public bool Update(SnackUpdateCommand snack) { var snackDb = SnackRepository.GetById(snack.Id); if (snackDb == null) { throw new NotFoundException("Registro não encontrado!"); } var seatEdit = Mapper.Map(snack, snackDb); return(SnackRepository.Update(seatEdit)); }