private async Task ExecuteAddCheeseCommand ()
		{
			try {
				AddCheeseCommand.ChangeCanExecute ();

				var newCheese = new Cheese () { 
					CheeseName = CheeseToAdd.CheeseName, 
					DairyName = CheeseToAdd.DairyName,
					DateAdded = DateTime.Now
				};

				newCheese = await _dataService.AddCheeseAsync (newCheese).ConfigureAwait (false);

				var newRating = new Rating () {
					CheeseId = newCheese.CheeseId,
					Notes = CheeseToAdd.Notes,
					WedgeRating = CheeseToAdd.WedgeRating,
					DateRated = DateTime.Now
				};

				newRating = await _dataService.RateCheeseAsync (newRating);

				CheeseToAdd.CheeseId = newRating.CheeseId;
				CheeseToAdd.RatingId = newRating.RatingId;

				Device.BeginInvokeOnMainThread (async () => {
					await Page.Navigation.PopModalAsync (true);
				});
			} catch (NoInternetException) {
				await Page.DisplayAlert ("No Internet!", "Cannot Access The Internet!", "Darn!");

			} finally {
				AddCheeseCommand.ChangeCanExecute ();
			}
		}
		public async Task<Rating> RateCheeseAsync (Rating ratedCheese)
		{
			if (!_isInitialized)
				await InitializeDataStore();

			ratedCheese.RatingId = Guid.NewGuid ().ToString ();

			await _sqliteConn.InsertAsync (ratedCheese);

			return ratedCheese;
		}
		public async Task<Rating> RateCheeseAsync (Rating ratedCheese)
		{
			if (!CrossConnectivity.Current.IsConnected)
				throw new NoInternetException();

			if (!_isInitialized)
				await InitializeDataStore ();

			await _client.GetTable<Rating> ().InsertAsync (ratedCheese);

			return ratedCheese;
		}
		public async Task<Rating> RateCheeseAsync (Rating ratedCheese)
		{
			if (!_isInitialized)
				await InitializeDataStore ();

			var rateSync = _client.GetSyncTable<Rating> ();

			await rateSync.InsertAsync (ratedCheese);

			// Push to Azure if connected
			if (CrossConnectivity.Current.IsConnected) {
				await _client.SyncContext.PushAsync ();
			}

			return ratedCheese;
		}
Пример #5
0
		private async Task ExecuteSaveRatingCommand ()
		{
			try {
				AddRatingCommand.ChangeCanExecute ();

				var rating = new Rating () {
					CheeseId = RatingToAdd.CheeseId,
					DateRated = DateTime.Now,
					Notes = RatingToAdd.Notes,
					WedgeRating = RatingToAdd.WedgeRating
				};

				rating = await _dataService.RateCheeseAsync (rating);

				RatingToAdd.RatingId = rating.RatingId;

				Device.BeginInvokeOnMainThread (async () => await Page.Navigation.PopModalAsync (true));
			} catch (NoInternetException) {
				await Page.DisplayAlert ("No Internet!", "Cannot Access The Internet!", "Darn!");

			} finally {
				AddRatingCommand.ChangeCanExecute ();
			}
		}