Ejemplo n.º 1
0
		public async static Task DeleteAppointmentSummary (AppointmentSummary appointmentSummary)
		{

			var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();

			await db.DeleteAsync (appointmentSummary);


		}
Ejemplo n.º 2
0
		//private static readonly AsyncLock Mutex = new AsyncLock ();


		public async static Task InsertApppointmentSummary (AppointmentSummary appointmentSummary)
		{

			var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
			await db.CreateTableAsync<AppointmentSummary> ();

			await db.InsertAsync (appointmentSummary);

		}
Ejemplo n.º 3
0
        public async Task Save(Appointment appointment)
        {
            AppointmentSummary[] UpdateAppointmentCatalogue(AppointmentSummary[] list, Appointment source)
            {
                AppointmentSummary appointmentSummary;

                // if found, update otherwise add-new
                if (list.Any(i => i.Id == source.Id))
                {
                    appointmentSummary = list.First(i => i.Id == source.Id);
                }
                else
                {
                    appointmentSummary = new AppointmentSummary();
                    list = list.Append(appointmentSummary).ToArray();
                }

                appointmentSummary.Id       = source.Id;
                appointmentSummary.Place    = source.Place;
                appointmentSummary.DateTime = source.DateTime;
                appointmentSummary.Deleted  = false;

                return(list);
            }

            var fileName = $"{appointment.Id}.json";

            await using (var file = File.CreateText($"{_storagePath}\\{fileName}"))
            {
                JsonSerializer serializer = new JsonSerializer();
                await new TaskFactory().StartNew(() =>
                {
                    serializer.Serialize(file, appointment);
                });
            }

            var appointmentCatalogue = await GetAppointmentSummaries();

            appointmentCatalogue = UpdateAppointmentCatalogue(appointmentCatalogue, appointment);

            await Save(appointmentCatalogue);
        }
Ejemplo n.º 4
0
        public async Task <AppointmentSummary[]> GetAppointmentSummaries()
        {
            var appointmentSummaryList = new AppointmentSummary[0];

            var fileName = $"{_storagePath}/{AppointmentCatalogueFileName}";

            if (File.Exists(fileName))
            {
                using (var catalogueFile = File.OpenText(fileName))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    await new TaskFactory().StartNew(() =>
                    {
                        appointmentSummaryList =
                            (AppointmentSummary[])serializer.Deserialize(catalogueFile, typeof(AppointmentSummary[]));
                    });
                }
            }

            return(appointmentSummaryList);
        }
Ejemplo n.º 5
0
		public async Task DeleteAppointmentSummary (AppointmentSummary appointmentSummary)
		{
			await AppointmentSummaryDAL.DeleteAppointmentSummary (appointmentSummary);
		}
Ejemplo n.º 6
0
		public  async Task InsertAppointmentSummary (AppointmentSummary appointmentSummary)
		{
			await AppointmentSummaryDAL.InsertApppointmentSummary (appointmentSummary);
		}
Ejemplo n.º 7
0
		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);
						});
					}
				});
			}

		}