// This function updates the occurance state locally and remotely. async void UpdateOccurance(Occurance occurance) { string url = AppConstants.BaseUrl + AppConstants.updateGoalAndRoutine; if (occurance.IsComplete != true) { occurance.updateIsInProgress(false); occurance.updateIsComplete(true); await RdsConnect.updateOccurance(occurance, false, true, url); } else { occurance.updateIsInProgress(false); occurance.updateIsComplete(false); await RdsConnect.updateOccurance(occurance, false, false, url); } }
//Used to update a goal/routine public static async Task <string> updateOccurance(Occurance currOccurance, bool inprogress, bool iscomplete, string url) { CheckTimeZone(); currOccurance.updateIsInProgress(inprogress); currOccurance.updateIsComplete(iscomplete); UpdateOccurance updateOccur = new UpdateOccurance(); updateOccur.id = currOccurance.Id; updateOccur.datetime_completed = currOccurance.Id; updateOccur.datetime_started = currOccurance.Id; updateOccur.is_in_progress = currOccurance.IsInProgress; updateOccur.is_complete = currOccurance.IsComplete; if (currOccurance.IsComplete == false && currOccurance.IsInProgress == false) { updateOccur.datetime_completed = ""; updateOccur.datetime_started = ""; } if (currOccurance.IsComplete == false && currOccurance.IsInProgress == true) { updateOccur.datetime_completed = ""; updateOccur.datetime_started = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt"); } if (currOccurance.IsComplete == true && currOccurance.IsInProgress == false) { updateOccur.datetime_completed = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt"); updateOccur.datetime_started = currOccurance.StartDayAndTime.ToString("yyyy-MM-dd hh:mm:ss tt"); } string toSend = updateOccur.updateOccurance(); Debug.WriteLine("LINE 85 " + toSend); var content = new StringContent(toSend); var res = await client.PostAsync(url, content); if (res.IsSuccessStatusCode) { Debug.WriteLine("Wrote to the datebase"); return("Success"); } else { Debug.WriteLine("Some error"); Debug.WriteLine(toSend); Debug.WriteLine(res.ToString()); return("Failure"); } //return "Failure"; }