/* * public int AddIngredient() { * string sql = "INSERT INTO whatsfordinner.ingredient(name, measure_type) VALUES (@name, @measure_type)"; * * NpgsqlCommand command = new NpgsqlCommand(sql, conn); * command.Parameters.AddWithValue("@name", "test1"); * command.Parameters.AddWithValue("@measure_type", "test2"); * * return NonQuery(command, "whatsfordinner.ingredient"); * } * * public int AddOneTestAccount() { * string sql = "INSERT INTO accounts(username, password, email, settings, preferences) VALUES (@username, @password, @email, @settings, @preferences)"; * * NpgsqlCommand command = new NpgsqlCommand(sql, conn); * command.Parameters.AddWithValue("@username", "andrejas"); * command.Parameters.AddWithValue("@password", "drdrois"); * command.Parameters.AddWithValue("@email", "*****@*****.**"); * command.Parameters.AddWithValue("@settings", "noget med settings"); * command.Parameters.AddWithValue("@preferences", "noget med preferences"); * * return NonQuery(command, "accounts"); * } * * public int AddTwoTestAccount() { * string sql = "INSERT INTO accounts(username, password, email, settings, preferences) VALUES (@username, @password, @email, @settings, @preferences), (@username, @password, @email, @settings, @preferences)"; * * NpgsqlCommand command = new NpgsqlCommand(sql, conn); * command.Parameters.AddWithValue("@username", "andrejas"); * command.Parameters.AddWithValue("@password", "drdrois"); * command.Parameters.AddWithValue("@email", "*****@*****.**"); * command.Parameters.AddWithValue("@settings", "noget med settings"); * command.Parameters.AddWithValue("@preferences", "noget med preferences"); * * return NonQuery(command, "accounts"); * } */ public static void dbMassEntityInsert() { DBController dbc = new DBController(); dbc.AddAccount(ModelDebug.GetTestAccount()); dbc.AddIngredient(ModelDebug.GetTestIngredient()); dbc.AddRetailer(ModelDebug.GetTestRetailer()); dbc.AddRecipe(ModelDebug.GetTestRecipe()); dbc.AddComment(ModelDebug.GetTestComment()); dbc.Close(); }
public void AddAccount(Account acc) { DBController dbc = new DBController(); try { dbc.AddAccount(acc); } catch (NpgsqlException e) { Console.WriteLine((Program.sqlDebugMessages) ? "AddAccount: " + e.BaseMessage.ToString() : ""); WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Conflict; ctx.OutgoingResponse.StatusDescription = e.BaseMessage; } finally { dbc.Close(); } }
public static void dbMassInsert() { DBController dbc = new DBController(); dbc.AddAccount(ModelDebug.GetTestAccount()); dbc.AddIngredient(ModelDebug.GetTestIngredient()); dbc.AddRetailer(ModelDebug.GetTestRetailer()); dbc.AddRecipe(ModelDebug.GetTestRecipe()); dbc.AddComment(ModelDebug.GetTestComment()); dbc.AddFavorises(ModelDebug.GetTestFavorises()); dbc.AddHasEaten(ModelDebug.GetTestHasEaten()); dbc.AddIngredientIn(ModelDebug.GetTestIngredientIn()); dbc.AddOffers(ModelDebug.GetTestOffers()); dbc.AddPictures(ModelDebug.GetTestPictures()); dbc.Close(); }