public async Task <string> DeleteIngredientAsync(string id) // tested
        {
            id.ValidateIfNull(ExceptionMessages.IdNull);
            var ingredient = await _context.Ingredients.FirstOrDefaultAsync(i => i.Id == id && i.DateDeleted == null);

            ingredient.ValidateIfNull(ExceptionMessages.IngredientNull);
            if (_context.CocktailComponent.Select(cc => cc.Ingredient.Id).Contains(id))
            {
                throw new MagicException("You cannot delete this ingredient");
            }
            _context.Remove(ingredient);
            await _context.SaveChangesAsync();

            return(ingredient.Name);
        }
Example #2
0
 public void Delete(TEntity entity) => Context.Remove(entity);