private static Day GetDayFromDR(NpgsqlDataReader dr) { int intDayID = Convert.ToInt32(dr["intDayID"]); DateTime dtmDate = (DateTime)dr["dtmDate"]; int intCalsLeft = Convert.ToInt32(dr["intCalsLeft"]); int intUserID = Convert.ToInt32(dr["intUserID"]); List <Meal> lstMealsAdded = MealDAL.GetMealsByDayAndUser(intDayID, intUserID).ToList(); List <WorkoutRoutine> lstWorkoutRoutines = null; // WorkoutRoutineDAL.GetExercisesByDayAndUser(intDayID, intUserID); int intExMinsLeft = Convert.ToInt32(dr["intExMinsLeft"]); Day day = Day.of(intDayID, lstMealsAdded, dtmDate, lstWorkoutRoutines, intCalsLeft, intExMinsLeft); return(day); }
public static bool AddMeal(Meal meal, int intUserID, int intDayID) { // insert into meal table int intNewMealID = MealDAL.InsertToMealTable(meal, intUserID); meal.intMealID = intNewMealID; // insert into foodMeal table with newly created meal ID & list of food // insert each item to food meal table foreach (var foodItem in meal.lstContents) { MealDAL.InsertToFoodMealTable(meal.intMealID, foodItem.intFoodItemID); } // insert into dayMeal table with newly created meal ID bool dayMealSuccess = MealDAL.InsertToDayMealTable(intNewMealID, intDayID); // subtract cals fron that day's cals left for that user bool subtractCalsSuccess = MealDAL.SubtractCals(meal.lstContents, intUserID, intDayID); //NpgsqlConnection conn = DatabaseConnection.GetConnection(); //conn.Open(); //// define a query //string query = ""; //NpgsqlCommand cmd = new NpgsqlCommand(query, conn); //cmd.Parameters.AddWithValue(""); //int result = cmd.ExecuteNonQuery(); //conn.Close(); //if (result == 1) // return true; //else // return false; return(dayMealSuccess && subtractCalsSuccess); }