private async void OnEnableMedTake(object obj) { Med_Take selectedMedTake = obj as Med_Take; if (selectedMedTake != null) { try { if (NetworkStatus.IsInternet()) { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Processing...", configuration: Common.LoadingDialogConfig)) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Common.SERVICE_CREDENTIALS)); using (HttpResponseMessage response = await client.PutAsync(Common.PUT_UPDATE_MED_TAKE_STATUS(selectedMedTake.Med_Take_ID, Convert.ToInt32(!selectedMedTake.IsActive)), null)) { if (response.IsSuccessStatusCode) { var jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { UpdateMedTakeEnableResult result = JsonConvert.DeserializeObject <UpdateMedTakeEnableResult>(jData); if (result.result > 0) { string message = String.Format("{0} updated!", selectedMedTake.Med_Name); await Common.ShowSnackbarMessage(message); } } } } } } } else { await Common.ShowMessageAsyncNetworkError(); } } catch (Exception error) { await Common.ShowMessageAsyncApplicationError(error.Message); } } }
private async Task ExecuteLoadMedTakesCommand() { IsBusy = true; try { if (NetworkStatus.IsInternet()) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Common.SERVICE_CREDENTIALS)); using (HttpResponseMessage response = await client.GetAsync(Common.GET_GET_MED_TAKES(PersistentSettings.AccountID))) { if (response.IsSuccessStatusCode) { var jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { GetMedTakesResult result = JsonConvert.DeserializeObject <GetMedTakesResult>(jData); if (result != null) { MedTakes.Clear(); foreach (var item in result.results) { MedTakes.Add(item); } } } } } } } else { await Common.ShowMessageAsyncNetworkError(); } } catch (Exception error) { await Common.ShowMessageAsyncApplicationError(error.Message); } finally { IsBusy = false; } }
private async void ExecuteLoadMedTakesCommand() { try { if (NetworkStatus.IsInternet()) { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading...", configuration: Common.LoadingDialogConfig)) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Common.SERVICE_CREDENTIALS)); using (HttpResponseMessage response = await client.GetAsync(Common.GET_GET_INTAKE_LOGS(PersistentSettings.AccountID))) { if (response.IsSuccessStatusCode) { var jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { GetIntakeLogsResult result = JsonConvert.DeserializeObject <GetIntakeLogsResult>(jData); if (result != null) { IntakeLogs = result.results; } } } } } } } else { await Common.ShowMessageAsyncNetworkError(); } } catch (Exception error) { await Common.ShowMessageAsyncApplicationError(error.Message); } }
private async void OnSubmitClicked() { if (CanSubmit) { IsBusy = true; try { if (Validate()) { if (NetworkStatus.IsInternet()) { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Sending feedback...", configuration: Common.LoadingDialogConfig)) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Common.SERVICE_CREDENTIALS)); AddRatingsRecommendationRequestObject obj = new AddRatingsRecommendationRequestObject { ratings = new Ratings_Recommendation { Account_ID = PersistentSettings.AccountID, Ratings = rate, Recommendation = recommendation } }; string serializedObject = JsonConvert.SerializeObject(obj, Formatting.Indented); using (HttpContent content = new StringContent(serializedObject, Encoding.UTF8, Common.HEADER_CONTENT_TYPE)) { using (HttpResponseMessage response = await client.PostAsync(Common.POST_ADD_RATINGS, content)) { if (response.IsSuccessStatusCode) { string jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { AddRatingsRecommendationResult result = JsonConvert.DeserializeObject <AddRatingsRecommendationResult>(jData); if (result.result > 0) { await Common.ShowAlertAsync("Thank you!", "Thank you for sending us your feedback.", "OK"); SetRate(0); Recommendation = string.Empty; Common.ShowNotification("Ratings Submission", "Thank you for your feedback!"); } } } } } } } } else { await Common.ShowMessageAsyncNetworkError(); } } else { ValidateMessage(); } } catch (Exception error) { await Common.ShowMessageAsyncApplicationError(error.Message); } finally { IsBusy = false; } } }
private async void OnMedTakeClicked(object obj) { var medtake = (Med_Take_Today)obj; if (!medtake.IsTaken) { bool cantake = true; if (medtake.IsTooEarly) { if (await Common.ShowAlertConfirmationWithButton("It's too early to take your medicine! Do you want to take it now?", "Yes", "No") == false) { cantake = false; } } if (cantake && await Common.ShowAlertConfirmationWithButton($"You should take {medtake.Dosage_Count} dosage(s) of {medtake.Med_Name}.", "OK", "No") == true) { try { if (NetworkStatus.IsInternet()) { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Taking Medicine...", configuration: Common.LoadingDialogConfig)) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(Common.SERVICE_CREDENTIALS)); string v = Common.PUT_TAKE_MEDICINE(medtake.Med_Take_Schedule_ID, medtake.Med_Take_ID); using (HttpResponseMessage response = await client.PutAsync(Common.PUT_TAKE_MEDICINE(medtake.Med_Take_Schedule_ID, medtake.Med_Take_ID), null)) { if (response.IsSuccessStatusCode) { var jData = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrWhiteSpace(jData)) { TakeMedicineResult result = JsonConvert.DeserializeObject <TakeMedicineResult>(jData); switch (result.result) { case 11: //Critical { await Common.ShowSnackbarMessage("Success!"); IsBusy = true; Common.ShowNotification($"{medtake.Med_Name} Count is Critical!", $"{medtake.Med_Name} needs to be replenished."); break; } case 22: //Not Critical { await Common.ShowSnackbarMessage("Success!"); IsBusy = true; break; } default: //Error { break; } } } } } } } } else { await Common.ShowMessageAsyncNetworkError(); } } catch (Exception error) { await Common.ShowMessageAsyncApplicationError(error.Message); } } } else if (medtake.IsTaken) { await Common.ShowAlertAsync("Taken Already", "You have already taken this medicine!", "Ok"); } }