/* * 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 AddRetailer(Retailer ret) { DBController dbc = new DBController(); try { dbc.AddRetailer(ret); } catch (NpgsqlException e) { Console.WriteLine((Program.sqlDebugMessages) ? "AddRetailer: " + e.BaseMessage.ToString() : ""); WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Conflict; ctx.OutgoingResponse.StatusDescription = e.BaseMessage; } finally { dbc.Close(); } }
public void save(List <Dealer> dealers, List <Store> stores, List <Offer> offers) { //Go through all eTilbudsAvisen stores and create equivalent Retailers from the data, recognized by the Database foreach (Store store in stores) { Retailer retailer = new Retailer(); retailer.GetOrSetLatitude = store.latitude.ToString(); retailer.GetOrSetLongitude = store.longitude.ToString(); //Fetch relevant data from the eTilbudsAvisen dealer, to fill in more blanks of Retailer foreach (Dealer dealer in dealers) { //Match the dealer id of store with the actual dealer if (store.dealer_id == dealer.Id) { retailer.GetOrSetCompanyName = dealer.Name; } } // Got no proper data for opening hours or description yet. retailer.GetOrSetOpeningHours = null; String categories; if (store.category_ids.Count != 0) { categories = store.category_ids[0]; for (int i = 1; i < store.category_ids.Count - 1; i++) { categories += ',' + store.category_ids[i]; } } else { categories = "No Categories"; } retailer.GetOrSetDescription = categories; //Put the retailer into the Database DBController dbc = new DBController(); int databaseId = dbc.AddRetailer(retailer); RetailerIdMap.Add(store.id, databaseId); dbc.Close(); } // Move on to convert and save all offers //saveOffers(offers); }
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(); }