private void submitButton_Clicked(object sender, EventArgs e) { // Get values from page string newDate = logDate; int newBreakfastCals = 0; int.TryParse(breakfastEntry.Text, out newBreakfastCals); int newLunchCals = 0; int.TryParse(lunchEntry.Text, out newLunchCals); int newDinnerCals = 0; int.TryParse(dinnerEntry.Text, out newDinnerCals); int newOtherCals = 0; int.TryParse(otherEntry.Text, out newOtherCals); string newNotes = notes.Text; if (!isInitializedLog) { Console.WriteLine("Creating new log"); CalorieLogInfo newLog = new CalorieLogInfo { date = logDate, isInitialized = true, breakfastCals = newBreakfastCals, lunchCals = newLunchCals, dinnerCals = newDinnerCals, otherCals = newOtherCals, notes = newNotes }; App.DatabaseAccess.CreateCalorieLog(newLog); isInitializedLog = true; } else { Console.WriteLine("Updating old log"); foundLogs = App.DatabaseAccess.FindCalorieLog(logDate); foundLogs[0].breakfastCals = newBreakfastCals; foundLogs[0].lunchCals = newLunchCals; foundLogs[0].dinnerCals = newDinnerCals; foundLogs[0].otherCals = newOtherCals; foundLogs[0].notes = newNotes; App.DatabaseAccess.UpdateCalorieLog(foundLogs[0]); } }
public void UpdateCalorieLog(CalorieLogInfo newLog) { try { conn.Update(newLog); Console.WriteLine("Updated calorie log."); } catch (Exception ex) { Console.WriteLine($"Failed to update calorie log.\nError message: {ex}"); } }
public void CreateCalorieLog(CalorieLogInfo newLog) { try { conn.Insert(newLog); Console.WriteLine("Created new calorie log!"); } catch (Exception ex) { Console.WriteLine($"Failed to create new calorie log.\nError message: {ex}"); } }