public async Task <string> AddCategory(RecipeCategoryDTO categoryAddDTO) { if (await CategoryExists(categoryAddDTO.Name)) { throw new ArgumentException("Category exists"); } await _context.AddAsync(_mapper.Map <RecipeCategory>(categoryAddDTO)); await Save(); return(categoryAddDTO.Name); }
/// <summary> /// </summary> /// <param name="recipeAddDTO"></param> /// <returns>Name of the recipe unless a recipe with this name already exists</returns> /// <exception cref="KeyNotFoundException"></exception> public async Task <string> AddRecipe(RecipeDTO recipeAddDTO) { if (await RecipeExists(recipeAddDTO.Name)) { throw new ArgumentException("Recipe exists"); } await _context.AddAsync(_mapper.Map <Recipe>(recipeAddDTO)); await Save(); _logger.LogInformation($"Added recipe {recipeAddDTO.Name}"); return(recipeAddDTO.Name); }
public async Task <string> AddRestaurantAsync(Restaurant restaurant) { await _context.AddAsync(restaurant); return(restaurant.Name); }