Пример #1
0
		//private static readonly AsyncLock Mutex = new AsyncLock ();

		public async static Task SaveEngagementNotesRecord (DateTime timeStamp, int gymID, int profileID, string note, int engagementNoteID, int userID, string staffName)
		{

			var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
			await db.CreateTableAsync<EngagementNotes> ();
			var currentRecord = await db.Table<EngagementNotes> ().Where (row => row.EngagementNoteID == engagementNoteID).FirstOrDefaultAsync ();
			if (currentRecord != null && currentRecord.Id != 0) {
				currentRecord.DateTime = timeStamp.ToString ();
				currentRecord.GymID = gymID;
				currentRecord.Note = note;
				currentRecord.ProfileID = profileID;
				currentRecord.EngagementNoteID = engagementNoteID;
				currentRecord.UserID = userID;
				currentRecord.StaffName = staffName;
				await db.UpdateAsync (currentRecord);
			} else {
				EngagementNotes engagementNote = new EngagementNotes ();
				engagementNote.DateTime = timeStamp.ToString ();
				engagementNote.GymID = gymID;
				engagementNote.Note = note;
				engagementNote.ProfileID = profileID;
				engagementNote.EngagementNoteID = engagementNoteID;
				engagementNote.UserID = userID;
				engagementNote.StaffName = staffName;
				await db.InsertAsync (engagementNote);
			}

		}
Пример #2
0
		public async static Task InsertEngagementRecord (EngagementNotes engagementNote)
		{

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

			await db.InsertAsync(engagementNote);

		}
Пример #3
0
		public async static Task SaveEngagementNotesRecordAndIncrementFailedCount (EngagementNotes engagementNote)
		{
			engagementNote.FailedSubmissionCount += 1;

			var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
			await db.CreateTableAsync<EngagementNotes> ();
			var currentRecord = await db.Table<EngagementNotes> ().Where (row => row.EngagementNoteID == engagementNote.EngagementNoteID).FirstOrDefaultAsync ();
			if (currentRecord != null && currentRecord.Id != 0) {

				await db.UpdateAsync (engagementNote);
			} else {

				await db.InsertAsync (engagementNote);
			}

		}
Пример #4
0
		private async void ExecuteDeleteEngagementNotesCommand(EngagementNotes engagementNote)
		{

			if (IsProcessing)
				return;

			IsProcessing = true;

			//first try deleting through the api if there is a network connection

			if (CrossConnectivity.Current.IsConnected)
			{
				//Delete member note in API
				int engagementNoteID = engagementNote.EngagementNoteID;
				var result = await CoachServices.DeleteEngagementNote(engagementNoteID);

				//Hard delete assuming deletion was successful on the server
				if (result == string.Empty)
				{
					await EngagementNotesDAL.DeleteEngagementNotes(engagementNote);
					var engagementNotesDB = await EngagementNotesDAL.GetEngagementNotes(SelectedUser.ProfileID);
					this.EngagementNotesList = new ObservableCollection<EngagementNotes>(engagementNotesDB);
				}
			}
			else {
				//Soft delete because deletion will not be in sync with the API
				engagementNote.IsSoftDeleted = true;
				await EngagementNotesDAL.ModifyEngagementRecord(engagementNote);
				var engagementNotesDB = await EngagementNotesDAL.GetEngagementNotes(SelectedUser.ProfileID);
				this.EngagementNotesList = new ObservableCollection<EngagementNotes>(engagementNotesDB);
			}

			await RefreshNotes();
			IsProcessing = false;
		}
Пример #5
0
		public async static Task DeleteEngagementNotes (EngagementNotes engagementNote)
		{

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

			await db.DeleteAsync (engagementNote);


		}
Пример #6
0
		static async Task<bool> SyncEngagementNotes (int gymID, bool returnValue)
		{
			var engagementNotesNoID = await EngagementNotesDAL.GetEngagementNotesWithNoServerID (gymID);
			foreach (var note in engagementNotesNoID) {
				try {
					List<EngagementNotes> engagementNotesList = new List<EngagementNotes> ();
					EngagementNotes engagementNotes = new EngagementNotes ();
					engagementNotes.DateTime = note.DateTime;
					engagementNotes.GymID = note.GymID;
					engagementNotes.Note = note.Note;
					engagementNotes.ProfileID = note.ProfileID;
					engagementNotes.StaffName = note.StaffName;
					engagementNotes.UserID = note.UserID;
					engagementNotesList.Add (engagementNotes);
					var engagementNotesResponseList = await CoachServices.PostEngagementNoteToServer (engagementNotesList);
					var engagementNotesResponse = engagementNotesResponseList [0];
					if (engagementNotesResponse.EngagementNoteID == 0) {
						await EngagementNotesDAL.SaveEngagementNotesRecordAndIncrementFailedCount (note);
					} else {
						await EngagementNotesDAL.SaveEngagementNotesRecord (Convert.ToDateTime (engagementNotesResponse.DateTime), engagementNotesResponse.GymID, engagementNotesResponse.ProfileID, engagementNotesResponse.Note, engagementNotesResponse.EngagementNoteID, engagementNotesResponse.UserID, engagementNotesResponse.StaffName);
					}
				} catch (Exception e) {
					await EngagementNotesDAL.SaveEngagementNotesRecordAndIncrementFailedCount (note);
					returnValue = false;
					Insights.Report(e);
				}
			}
			return returnValue;
		}
Пример #7
0
		private async void ExecuteSaveNoteCommand ()
		{

			if (IsProcessing)
				return;

			IsProcessing = true;

			string staffName = App.WorkoutCreatorContext.StaffMember.FirstName + " " + App.WorkoutCreatorContext.StaffMember.LastName;
			int userID = App.WorkoutCreatorContext.StaffMember.StaffID;

			if (CrossConnectivity.Current.IsConnected) {
				//Save note on the server through API

				List<EngagementNotes> engagementNotesDTOList = new List<EngagementNotes> ();

				EngagementNotes engagementNote = new EngagementNotes();
				engagementNote.DateTime = DateTime.Now.ToString();
				engagementNote.GymID = App.WorkoutCreatorContext.StaffMember.GymID;
				engagementNote.Note = Note;
				engagementNote.ProfileID = SelectedUser.ProfileID;
				engagementNote.StaffName = staffName;
				engagementNote.UserID = userID;

				engagementNotesDTOList.Add (engagementNote);


				var submittedEngagementNoteResponseList = await CoachServices.PostEngagementNoteToServer (engagementNotesDTOList);

				var submittedEngagementNoteResponse = submittedEngagementNoteResponseList [0];

				await EngagementNotesDAL.SaveEngagementNotesRecord (Convert.ToDateTime(submittedEngagementNoteResponse.DateTime),submittedEngagementNoteResponse.GymID,submittedEngagementNoteResponse.ProfileID,submittedEngagementNoteResponse.Note,submittedEngagementNoteResponse.EngagementNoteID, engagementNote.UserID, engagementNote.StaffName);

			} else {

				EngagementNotes engagementNote = new EngagementNotes();
				engagementNote.DateTime = DateTime.Now.ToString();
				engagementNote.GymID = App.WorkoutCreatorContext.StaffMember.GymID;
				engagementNote.Note = Note;
				engagementNote.ProfileID = SelectedUser.ProfileID;
				engagementNote.StaffName = staffName;
				engagementNote.UserID = userID;
				await EngagementNotesDAL.InsertEngagementRecord (engagementNote);

			}

			MessagingCenter.Send<mpAddNotePage> (Application.Current.MainPage.Navigation.NavigationStack.Last() as mpAddNotePage, "NoteAdded");

			await Application.Current.MainPage.Navigation.PopAsync(true);

			IsProcessing = false;

		}