public bool AddVitamin(Vitamin vitamin) { NpgsqlConnection con = connectionPostgres.GetConnection(); con.Open(); NpgsqlCommand command = new NpgsqlCommand(INSER_INTO_VITAMINS, con); command.Parameters.AddWithValue(":id", vitamin.VitaminID); command.Parameters.AddWithValue(":name", vitamin.Name); bool value = (command.ExecuteNonQuery() > 0); con.Close(); return(value); }
public bool AddUser(User user) { NpgsqlConnection con = connection.GetConnection(); con.Open(); NpgsqlCommand command = new NpgsqlCommand(INSERT_INTO_USER_MEAL, con); command.Parameters.AddWithValue(":username", user.Name); command.Parameters.AddWithValue(":password", user.Password); command.Parameters.AddWithValue(":date", DateTime.Now); bool value = (command.ExecuteNonQuery() > 0); con.Close(); return(value); }
public bool AddFood(Food food) { NpgsqlConnection con = connectionPostgres.GetConnection(); con.Open(); NpgsqlCommand command = new NpgsqlCommand(INSERT_INTO_FOOD, con); command.Parameters.AddWithValue(":id", food.FoodID); command.Parameters.AddWithValue(":name", food.Name); command.Parameters.AddWithValue(":amount", food.Amount); command.Parameters.AddWithValue(":calories", food.Calories); command.Parameters.AddWithValue(":carbs", food.Carbs); command.Parameters.AddWithValue(":protein", food.Protein); command.Parameters.AddWithValue(":fat", food.Fat); bool value = (command.ExecuteNonQuery() > 0); con.Close(); return(value); }
public List <Meal> GetAllMealsFromUser(User user) { NpgsqlConnection con = connectionPostgres.GetConnection(); con.Open(); NpgsqlCommand command = new NpgsqlCommand(String.Format(SELECT_ALL_MEALS_FROM_USER, user.Name), con); NpgsqlDataReader dr = command.ExecuteReader(); List <Meal> listMeal = new List <Meal>(); while (dr.Read()) { Meal meal = new Meal() { Id = int.Parse(dr[0].ToString()), Date = DateTime.Parse(dr[2].ToString()) }; meal.Foods = GetMealFoods(meal); listMeal.Add(meal); } con.Close(); return(listMeal); }