public static async Task ListMedicalPractioner(StackLayout Stack, MedicalPractitionerType MPType) { Device.BeginInvokeOnMainThread(delegate { Stack.Children.Clear(); }); //posting empty values as the PostAsync requires a FormUrlEncodedContent Dictionary <int, String[]> Data = new Dictionary <int, string[]> { { 0, new String[] { "n/a", "n/a" } }, }; String ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), (MPType == MedicalPractitionerType.Doctor)? "user/search/medics" : "user/search/institutions"); var DecodedJson = JObject.Parse(ResponseJson); await Utilities.RunTask(async delegate { foreach (var Medic in DecodedJson["medics"]) { String MedicBioData = (MPType == MedicalPractitionerType.Doctor) ? await MedicalPractitionerController.GetBioDetails((int)Medic["medic"]["id"]) : "No Bio Data Provided"; MedicBioData = (String.IsNullOrEmpty(MedicBioData) ? "No Bio Data provided." : MedicBioData); Device.BeginInvokeOnMainThread(() => { ///only add the child if it is of the same specialty type //if ( Enum.GetName(typeof(MedicalPractitionerType),MPType) == ((MPType == MedicalPractitionerType.Doctor) ? Enum.GetName(typeof(MedicalPractitionerType), Medic["medic"]["specialty"]) : Enum.GetName(typeof(MedicalPractitionerType), Medic["specialty"]))) Stack.Children.Add(MedPractListTemplate.ListTemplate02((MPType == MedicalPractitionerType.Doctor) ? (int)Medic["medic"]["id"] : (int)Medic["id"], MPType, Medic["name"].ToString(), (MedicBioData.Length >= 25) ? MedicBioData.Substring(0, 25) : MedicBioData, new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), (MPType == MedicalPractitionerType.Doctor) ? Convert.ToDouble(Medic["medic"]["charge"]) : 0, String.Empty)); if (MPType == MedicalPractitionerType.Doctor) { Stack.Children.Add(MedPractListTemplate.ListTemplate02((MPType == MedicalPractitionerType.Doctor) ? (int)Medic["medic"]["id"] : (int)Medic["id"], MPType, Medic["name"].ToString(), (MedicBioData.Length >= 25) ? MedicBioData.Substring(0, 25) : MedicBioData, new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), (MPType == MedicalPractitionerType.Doctor) ? Convert.ToDouble(Medic["medic"]["charge"]) : 0, String.Empty)); } else { if (Enum.GetName(typeof(MedicalPractitionerType), MPType).ToLower() == Medic["category"].ToString().ToLower()) { Stack.Children.Add(MedPractListTemplate.ListTemplate02((int)Medic["id"], MPType, Medic["name"].ToString(), (MedicBioData.Length >= 25) ? MedicBioData.Substring(0, 25) : MedicBioData, new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), 0, String.Empty)); } } }); } }); }
public static async Task SearchMedicalPractioner(String Name, MedicalPractitionerType MPType, StackLayout Stack) { Device.BeginInvokeOnMainThread(delegate { Stack.Children.Clear(); }); Dictionary <int, String[]> Data = new Dictionary <int, string[]> { { 0, new String[] { "name", Name } }, }; String ResponseJson = await GeneralModel.PostAsync(Utilities.PostDataEncoder(Data), (MPType == MedicalPractitionerType.Doctor)? "user/search/medics" : "user/search/institutions"); var DecodedJson = JObject.Parse(ResponseJson); await Utilities.RunTask(async delegate { foreach (var Medic in DecodedJson["medics"]) { String MedicBioData = (MPType == MedicalPractitionerType.Doctor) ? await MedicalPractitionerController.GetBioDetails((int)Medic["medic"]["id"]) : "No Bio Data Provided"; MedicBioData = (String.IsNullOrEmpty(MedicBioData) ? "No Bio Data provided." : MedicBioData); Device.BeginInvokeOnMainThread(() => { Stack.Children.Add(MedPractListTemplate.ListTemplate02((int)Medic["medic"]["id"], MPType, Medic["name"].ToString(), MedicBioData.Substring(0, 25), new Random().Next(1, 6), Utilities.Source("doc_anim.jpg", typeof(AppointmentController)), 4.1, Medic["address"].ToString(), Convert.ToDouble(Medic["medic"]["charge"]), String.Empty)); }); } }); //no result Device.BeginInvokeOnMainThread(delegate { if (Stack.Children.Count == 0) { Stack.Children.Add(new Label { Text = "Search returned no result. Please verify supplied name.", Style = App.Current.Resources["_EmptyLabelTemplate"] as Style }); } }); }