public async Task <IngredientDB> Add(IngredientDB recipe) { try { using (var dbConnection = new NpgsqlConnection(connectionStringMain)) { await dbConnection.OpenAsync(); var result = await dbConnection.QueryFirstAsync <IngredientDB>(@"SELECT * FROM ""Ingredient_Insert""" + "(@name,@products,@url,@id,@known)", new { name = recipe.name, products = recipe.products, url = recipe.url, id = recipe.id, known = recipe.known }); return(result); } } catch (NpgsqlException e) { _logger.LogError(e, "Failed to add recipe."); throw; } catch (Exception e) { _logger.LogError(e, "Failed to add recipe."); throw; } }
public async Task <IngredientDB> AddIngredients(IngredientDB ingredients) { RecipeRepository repo = new RecipeRepository(_config, _loggerFactory); var response = await repo.Add(ingredients); return(response); }
public void CheckIfDrinkNameExists() { //setup DrinkDB drinkDB = new DrinkDB(); List <String> names = new List <string>(); names.Add("testJuiceVodka"); Ingredient testVodka = new Ingredient("testVodka", true, 37); Ingredient testJuice = new Ingredient("testJuice", true, 0); IngredientDB ingredientDB = new IngredientDB(); ingredientDB.Insert(testVodka); ingredientDB.Insert(testJuice); MeasurementDB measurementDB = new MeasurementDB(); Measurement measurement = measurementDB.Find("cl"); QuantifiedIngredient quantifiedIngredientVodka = new QuantifiedIngredient(8, testVodka, measurement); QuantifiedIngredient quantifiedIngredientJuice = new QuantifiedIngredient(16, testJuice, measurement); List <QuantifiedIngredient> quantifiedIngredientsList = new List <QuantifiedIngredient>(); quantifiedIngredientsList.Add(quantifiedIngredientVodka); quantifiedIngredientsList.Add(quantifiedIngredientJuice); Drink drink = new Drink(names, quantifiedIngredientsList, "Bland"); Drink drinkWithId = drinkDB.Insert(drink); drinkDB.InsertDrinkNames(names.First(), drinkWithId.Id); QuantifiedIngredientDB quantifiedIngredientDB = new QuantifiedIngredientDB(); quantifiedIngredientDB.Insert(quantifiedIngredientsList, drinkWithId.Id); //act bool drinkNameExists = drinkDB.CheckDrinkName(drinkWithId.Names.First()); //assert Assert.AreEqual(drinkNameExists, true); }