コード例 #1
0
		public async static Task SaveMemberBarriersAndIncrementFailedCount (MemberBarriers memberBarrier)
		{

			var db = DependencyService.Get<ISQLite> ().GetAsyncConnection ();
			await db.CreateTableAsync<MemberBarriers> ();
			var currentRecord = await db.Table<MemberBarriers> ().Where (row => row.BarrierID == memberBarrier.BarrierID).FirstOrDefaultAsync ();
			if (currentRecord != null && currentRecord.Id != 0) {
				currentRecord.BarrierID = memberBarrier.BarrierID;
				currentRecord.BarrierSetDate = memberBarrier.BarrierSetDate;
				currentRecord.BarrierValue = memberBarrier.BarrierValue;
				currentRecord.FailedCount = memberBarrier.FailedCount;
				currentRecord.BarrierDisplayValue = memberBarrier.BarrierDisplayValue;
				currentRecord.Id = memberBarrier.Id;
				currentRecord.IsSoftDeleted = memberBarrier.IsSoftDeleted;
				currentRecord.MemberBarrierValueID = memberBarrier.MemberBarrierValueID;
				currentRecord.ProfileID = memberBarrier.ProfileID;

				currentRecord.FailedCount += 1;

				await db.UpdateAsync (currentRecord);
			} else {
				memberBarrier.FailedCount += 1;
				await db.InsertAsync (memberBarrier);
			}

		}
コード例 #2
0
		public async static Task DeleteMemberBarriers (MemberBarriers memberBarrier)
		{

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

			await db.DeleteAsync (memberBarrier);


		}
コード例 #3
0
		public BarrierStrategyModal (User selectedUser, BarriersAvailable barrierAvailable, MemberBarriers memberBarrier = null)
		{
			InitializeComponent ();
			_viewModel = new BarrierStrategyViewModel (selectedUser, barrierAvailable, this, memberBarrier);

			this.BindingContext = _viewModel;



		}
コード例 #4
0
		public BarrierStrategyViewModel(User selectedUser, BarriersAvailable barrierAvailable, Page page, MemberBarriers memberBarrier = null)
		{
			SelectedUser = selectedUser;
			BarrierAvailableProperty = barrierAvailable;

			PageProperty = page;
			if (memberBarrier == null) {
				BarrierName = barrierAvailable.BarrierIDTitle;
				memberBarrier = new MemberBarriers ();
				memberBarrier.BarrierDisplayValue = BarrierAvailableProperty.BarrierIDTitle;
				memberBarrier.BarrierID = BarrierAvailableProperty.BarrierID;
				memberBarrier.ProfileID = selectedUser.ProfileID;
			} else {
				BarrierName = memberBarrier.BarrierDisplayValue;
			}
			MemberBarrier = memberBarrier;
		}
コード例 #5
0
		private async void AddBarrier()
		{

			List<MemberBarriers> memberBarriersDTOList = new List<MemberBarriers> ();

			MemberBarriers memberBarriersDTO = new MemberBarriers ();

			memberBarriersDTO.MemberBarrierValueID = MemberBarrier.MemberBarrierValueID;
			memberBarriersDTO.BarrierID = MemberBarrier.BarrierID;
			memberBarriersDTO.BarrierSetDate = DateTime.Now.ToString();
			memberBarriersDTO.BarrierValue = MemberBarrier.BarrierValue;
			memberBarriersDTO.ProfileID = MemberBarrier.ProfileID;


			memberBarriersDTOList.Add (memberBarriersDTO);

			if (CrossConnectivity.Current.IsConnected) {
				var resultList = await CoachServices.SaveMemberBarriersToServer (memberBarriersDTOList);
				memberBarriersDTO.MemberBarrierValueID = resultList [0].MemberBarrierValueID;
			}
				
			MemberBarrier.MemberBarrierValueID = memberBarriersDTO.MemberBarrierValueID;

			await MemberBarriersDAL.SaveMemberBarriers (MemberBarrier);

			MessagingCenter.Send<BarrierStrategyModal> (PageProperty as BarrierStrategyModal, "BarrierStrategyAdded");
		}
コード例 #6
0
		public mpBarriersViewModel(User selectedUser)
		{
			SelectedUser = selectedUser;
			//get the Member Image
			if (SelectedUser.ImageURL == null || SelectedUser.ImageURL == "")
			{
				MemberImage = "memberpic.png";

			}
			else {

				MemberImage = SelectedUser.ImageURL;
			}
			AvailableBarriersList = new ObservableCollection<BarriersAvailable>();
			MemberBarriersList = new ObservableCollection<MemberBarriers>();
			if (CrossConnectivity.Current.IsConnected)
			{
				Task.Run(async () =>
			   {

				   var availableBarriersListAPI = await CoachServices.GetAvailableBarriers();
				   var memberBarriersListAPI = await CoachServices.GetMemberBarriers(SelectedUser.ProfileID);

				   //If available barriers returned from the API delete all barriers from local database
				   if (availableBarriersListAPI.Count() > 0)
				   {
					   var barriersAvailableToDeleteDB = await BarriersAvailableDAL.GetBarriersAvailable();
					   foreach (var barrierToDelete in barriersAvailableToDeleteDB)
					   {
						   await BarriersAvailableDAL.DeleteBarriersAvailable(barrierToDelete);
					   }
				   }

				   //If member barriers returned from the API delete all barriers from local database
				   if (memberBarriersListAPI.Count() > 0)
				   {
					   var memberBarriersToDeleteDB = await MemberBarriersDAL.GetMemberBarriers(SelectedUser.ProfileID);
					   foreach (var barrierToDelete in memberBarriersToDeleteDB)
					   {
						   if (!barrierToDelete.IsSoftDeleted)
						   {
							   await MemberBarriersDAL.DeleteMemberBarriers(barrierToDelete);
						   }
					   }
				   }
				   foreach (var availablebarrierDTO in availableBarriersListAPI)
				   {
					   BarriersAvailable availableBarrier = new BarriersAvailable();
					   availableBarrier.BarrierID = availablebarrierDTO.BarrierID;
					   availableBarrier.BarrierIDTitle = availablebarrierDTO.BarrierIDTitle;

					   await BarriersAvailableDAL.SaveBarriersAvailable(availableBarrier);
				   }

				   var barriersAvailableDB = await BarriersAvailableDAL.GetBarriersAvailable();
				   AvailableBarriersList = new ObservableCollection<BarriersAvailable>(barriersAvailableDB);

				   foreach (var memberBarrierDTO in memberBarriersListAPI)
				   {
					   MemberBarriers memberBarrier = new MemberBarriers();
					   //Start here
					   memberBarrier.BarrierID = memberBarrierDTO.BarrierID;
					   memberBarrier.BarrierSetDate = memberBarrierDTO.BarrierSetDate;
					   memberBarrier.BarrierValue = memberBarrierDTO.BarrierValue;

					   string barrierName = AvailableBarriersList.First(row => row.BarrierID == memberBarrier.BarrierID).BarrierIDTitle;
					   memberBarrier.BarrierDisplayValue = barrierName;

					   memberBarrier.MemberBarrierValueID = memberBarrierDTO.MemberBarrierValueID;
					   memberBarrier.ProfileID = memberBarrierDTO.ProfileID;

					   await MemberBarriersDAL.SaveMemberBarriers(memberBarrier);
				   }
			   });
			}
			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 barriersAvailableDB = await BarriersAvailableDAL.GetBarriersAvailable();
					AvailableBarriersList = new ObservableCollection<BarriersAvailable>(barriersAvailableDB);

					var memberBarriersDB = await MemberBarriersDAL.GetMemberBarriers(SelectedUser.ProfileID);
					MemberBarriersList = new ObservableCollection<MemberBarriers>(memberBarriersDB);
				});
			}
		}
コード例 #7
0
		private async void ExecuteDeleteMemberBarrierCommand(MemberBarriers memberBarrier)
		{

			if (IsProcessing)
				return;

			IsProcessing = true;

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

			if (CrossConnectivity.Current.IsConnected)
			{
				//Delete member barrier in API
				int memberBarrierValueID = memberBarrier.MemberBarrierValueID;

				//Start here
				var result = await CoachServices.DeleteMemberBarrier(memberBarrierValueID);

				//Hard delete assuming deletion was successful on the server
				if (result == string.Empty)
				{
					await MemberBarriersDAL.DeleteMemberBarriers(memberBarrier);
					var memberBarriersDB = await MemberBarriersDAL.GetMemberBarriers(SelectedUser.ProfileID);
					MemberBarriersList = new ObservableCollection<MemberBarriers>(memberBarriersDB);
				}
			}
			else {
				//Soft delete because deletion will not be in sync with the API
				memberBarrier.IsSoftDeleted = true;
				await MemberBarriersDAL.SaveMemberBarriers(memberBarrier);
				var memberBarriersDB = await MemberBarriersDAL.GetMemberBarriers(SelectedUser.ProfileID);
				MemberBarriersList = new ObservableCollection<MemberBarriers>(memberBarriersDB);
			}

			IsProcessing = false;

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

		}
コード例 #8
0
ファイル: DataSyncManager.cs プロジェクト: MobileFit/CoachV2
		static async Task<bool> SyncMemberBarriers (int gymID, bool returnValue)
		{
			var memberBarriersNoServerID = await MemberBarriersDAL.GetMemberBarriersNoMemberBarrierValueID ();
			foreach (var barrier in memberBarriersNoServerID) {
				try {
					List<MemberBarriers> memberBarriersDTOList = new List<MemberBarriers> ();
					MemberBarriers memberBarriersDTO = new MemberBarriers ();
					memberBarriersDTO.BarrierID = barrier.BarrierID;
					memberBarriersDTO.BarrierSetDate = barrier.BarrierSetDate;
					memberBarriersDTO.BarrierValue = barrier.BarrierValue;
					memberBarriersDTO.ProfileID = barrier.ProfileID;
					memberBarriersDTOList.Add (memberBarriersDTO);
					var resultList = await CoachServices.SaveMemberBarriersToServer (memberBarriersDTOList);
					barrier.MemberBarrierValueID = resultList [0].MemberBarrierValueID;
					if (barrier.MemberBarrierValueID == 0) {
						await MemberBarriersDAL.SaveMemberBarriersAndIncrementFailedCount (barrier);
					} else {
						await MemberBarriersDAL.SaveMemberBarriers (barrier);
					}
				} catch (Exception e) {
					await MemberBarriersDAL.SaveMemberBarriersAndIncrementFailedCount (barrier);
					returnValue = false;
					Insights.Report(e);
				}
			}
			return returnValue;
		}