public ResponseSummaryViewModel (User selectedUser) { SelectedUser = selectedUser; //get the Member Image if (SelectedUser.ImageURL == null || SelectedUser.ImageURL == "") { MemberImage = "memberpic.png"; } else { MemberImage = SelectedUser.ImageURL; } ResponseQuestionList = new ObservableCollection<ResponseSummary> (); ResponseSummaryGroupList = new ObservableCollection<ResponseSummaryGroup> (); AppointmentSummaryList = new ObservableCollection<AppointmentSummary> (); AppointmentSummaryGroupList = new ObservableCollection<AppointmentSummaryGroup> (); if (CrossConnectivity.Current.IsConnected) { Task.Run (async() => { var responseSummaryDBList = await ResponseSummaryDAL.GetResponseSummary (SelectedUser.ProfileID); foreach (var responseSummaryDB in responseSummaryDBList) { await ResponseSummaryDAL.DeleteResponseSummary (responseSummaryDB); } var responseSummaryListAPI = await CoachServices.RequestResponseSummary (SelectedUser.ProfileID); foreach (var responseSummaryDTO in responseSummaryListAPI) { ResponseSummary responseSummary = new ResponseSummary (responseSummaryDTO); await ResponseSummaryDAL.InsertResponseSummary (responseSummary); } var responseSummaryDBList2 = await ResponseSummaryDAL.GetResponseSummary (SelectedUser.ProfileID); ResponseQuestionList = new ObservableCollection<ResponseSummary> (responseSummaryDBList2); foreach (var sum in ResponseQuestionList) { var responseArray = sum.MemberResponse.Split (','); for (int i = 0; i < responseArray.Count (); i++) { responseArray [i] = responseArray [i].Trim (); } sum.MemberResponseList = responseArray.ToList (); } foreach (var rSumm in ResponseQuestionList) { ResponseSummaryGroup responseSummaryGroup = new ResponseSummaryGroup (rSumm); Device.BeginInvokeOnMainThread (() => { ResponseSummaryGroupList.Add (responseSummaryGroup); }); } var appointmentSummaryDBList = await AppointmentSummaryDAL.GetAppointmentSummaryList (SelectedUser.ProfileID); foreach (var appointmentSummaryDB in appointmentSummaryDBList) { await AppointmentSummaryDAL.DeleteAppointmentSummary (appointmentSummaryDB); } var appointmentSummaryListAPI = await CoachServices.RequestAppointmentSummary (SelectedUser.ProfileID); foreach (var appointmentSummaryDTO in appointmentSummaryListAPI) { AppointmentSummary appointmentSummary = new AppointmentSummary (appointmentSummaryDTO); await AppointmentSummaryDAL.InsertApppointmentSummary (appointmentSummary); } var appointmentSummaryDBList2 = await AppointmentSummaryDAL.GetAppointmentSummaryList (SelectedUser.ProfileID); AppointmentSummaryList = new ObservableCollection<AppointmentSummary> (appointmentSummaryDBList2); var distinctAppointmentNames = AppointmentSummaryList.Select(row => row.TypeName).Distinct(); if(ResponseSummaryGroupList.Count() > 0) { AppointmentSummaryGroup tourGroup = new AppointmentSummaryGroup(ResponseSummaryGroupList, "Tour"); Device.BeginInvokeOnMainThread(() => { AppointmentSummaryGroupList.Add(tourGroup); }); } foreach(var appointmentName in distinctAppointmentNames) { var appointmentSummaryList = AppointmentSummaryList.Where(row => row.TypeName == appointmentName).ToList(); AppointmentSummaryGroup appointmentSummaryGroup = new AppointmentSummaryGroup(appointmentSummaryList); Device.BeginInvokeOnMainThread(() => { AppointmentSummaryGroupList.Add(appointmentSummaryGroup); }); } }); } else { DependencyService.Get<ICustomDialog> ().Display ("You are not connected to a network. The displayed data might not be up to date.", "OK"); Task.Run (async() => { var responseSummaryDBList = await ResponseSummaryDAL.GetResponseSummary (SelectedUser.ProfileID); ResponseQuestionList = new ObservableCollection<ResponseSummary> (responseSummaryDBList); foreach (var sum in ResponseQuestionList) { var responseArray = sum.MemberResponse.Split (','); for (int i = 0; i < responseArray.Count (); i++) { responseArray [i] = responseArray [i].Trim (); } sum.MemberResponseList = responseArray.ToList (); } foreach (var rSumm in ResponseQuestionList) { ResponseSummaryGroup responseSummaryGroup = new ResponseSummaryGroup (rSumm); Device.BeginInvokeOnMainThread (() => { ResponseSummaryGroupList.Add (responseSummaryGroup); }); } var appointmentSummaryDBList2 = await AppointmentSummaryDAL.GetAppointmentSummaryList (SelectedUser.ProfileID); AppointmentSummaryList = new ObservableCollection<AppointmentSummary> (appointmentSummaryDBList2); var distinctAppointmentNames = AppointmentSummaryList.Select(row => row.TypeName).Distinct(); if(ResponseSummaryGroupList.Count() > 0) { AppointmentSummaryGroup tourGroup = new AppointmentSummaryGroup(ResponseSummaryGroupList, "Tour"); Device.BeginInvokeOnMainThread(() => { AppointmentSummaryGroupList.Add(tourGroup); }); } foreach(var appointmentName in distinctAppointmentNames) { var appointmentSummaryList = AppointmentSummaryList.Where(row => row.TypeName == appointmentName).ToList(); AppointmentSummaryGroup appointmentSummaryGroup = new AppointmentSummaryGroup(appointmentSummaryList); Device.BeginInvokeOnMainThread(() => { AppointmentSummaryGroupList.Add(appointmentSummaryGroup); }); } }); } }
public AppointmentSummaryViewModel (User selectedUser) { SelectedUser = selectedUser; //get the Member Image if(SelectedUser.ImageURL == null || SelectedUser.ImageURL == ""){ MemberImage = "memberpic.png"; }else{ MemberImage = SelectedUser.ImageURL; } AppointmentSummaryList = new ObservableCollection<AppointmentSummary> (); AppointmentSummaryGroupList = new ObservableCollection<AppointmentSummaryGroup> (); if (CrossConnectivity.Current.IsConnected) { Task.Run (async() => { var appointmentSummaryDBList = await Manager.Instance.AppointmentSummary.GetAppointmentSummaryList (SelectedUser.ProfileID); foreach (var appointmentSummaryDB in appointmentSummaryDBList) { await Manager.Instance.AppointmentSummary.DeleteAppointmentSummary (appointmentSummaryDB); } var appointmentSummaryListAPI = await CoachServices.RequestAppointmentSummary ("MemberInformation/AppointmentFormSummary/ProfileID/" + SelectedUser.ProfileID.ToString ()); foreach (var appointmentSummaryDTO in appointmentSummaryListAPI) { AppointmentSummary appointmentSummary = new AppointmentSummary (appointmentSummaryDTO); await Manager.Instance.AppointmentSummary.InsertAppointmentSummary (appointmentSummary); } var appointmentSummaryDBList2 = await Manager.Instance.AppointmentSummary.GetAppointmentSummaryList (SelectedUser.ProfileID); AppointmentSummaryList = new ObservableCollection<AppointmentSummary> (appointmentSummaryDBList2); var distinctAppointmentNames = AppointmentSummaryList.Select(row => row.TypeName).Distinct(); foreach(var appointmentName in distinctAppointmentNames) { var appointmentSummaryList = AppointmentSummaryList.Where(row => row.TypeName == appointmentName).ToList(); AppointmentSummaryGroup appointmentSummaryGroup = new AppointmentSummaryGroup(appointmentSummaryList); Device.BeginInvokeOnMainThread(() => { AppointmentSummaryGroupList.Add(appointmentSummaryGroup); }); } }); } else { DependencyService.Get<ICustomDialog> ().Display ("You are not connected to a network. The displayed data might not be up to date.", "OK"); Task.Run (async() => { var appointmentSummaryDBList2 = await Manager.Instance.AppointmentSummary.GetAppointmentSummaryList (SelectedUser.ProfileID); AppointmentSummaryList = new ObservableCollection<AppointmentSummary> (appointmentSummaryDBList2); var distinctAppointmentNames = AppointmentSummaryList.Select(row => row.TypeName).Distinct(); foreach(var appointmentName in distinctAppointmentNames) { var appointmentSummaryList = AppointmentSummaryList.Where(row => row.TypeName == appointmentName).ToList(); AppointmentSummaryGroup appointmentSummaryGroup = new AppointmentSummaryGroup(appointmentSummaryList); Device.BeginInvokeOnMainThread(() => { AppointmentSummaryGroupList.Add(appointmentSummaryGroup); }); } }); } }