public async Task AddToppingToPizza(int pizzaId, int ingredientId) { var pizza = await _pizzaRepository.GetByIdAsync(pizzaId); if (pizza == null) { throw new EntityCantBeLoadedException <Pizza>(pizzaId.ToString()); } var ingredient = await _ingredientRepository.GetByIdAsync(ingredientId); if (ingredient == null) { throw new EntityCantBeLoadedException <Ingredient>(ingredientId.ToString()); } var topping = await _pizzaToppingRepository.GetToppingAsync(pizzaId, ingredientId); if (topping != null) { throw new EntityAlreadyExistsException <PizzaTopping>($"{{{pizzaId}, {ingredientId}}}"); } await _pizzaToppingRepository.AddAsync(new PizzaTopping() { PizzaId = pizzaId, IngredientId = ingredientId }); }
public async Task <IngredientDto> GetIngredientByIdAsync(int id) { var ingredient = await _ingredientRepository.GetByIdAsync(id); return(_mapper.Map <IngredientDto>(ingredient)); }
public virtual async Task <IngredientCommandResult> GetByIdAsync(int id) { return(await _repository.GetByIdAsync(id)); }