コード例 #1
0
		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 ();
			}
		}
コード例 #2
0
		public AddRatingViewModel (Cheese cheese, ContentPage page)
		{
			_dataService = DependencyService.Get<ICheeseDataService> ();

			RatingToAdd = new CheeseAndRating () {
				CheeseId = cheese.CheeseId,
				CheeseName = cheese.CheeseName,
				DairyName = cheese.DairyName
			};

			Page = page;
		}
コード例 #3
0
        public AddRatingView(Cheese cheese)
        {
            _viewModel     = new AddRatingViewModel(cheese, this);
            BindingContext = _viewModel;


            var cheeseName = new Label();

            cheeseName.Text = string.Format("The cheese name is {0}", _viewModel.RatingToAdd.CheeseName);

            var dairyName = new Label()
            {
                Text = "Dairy Name"
            };

            dairyName.Text = string.Format("The dairy name is {0}", _viewModel.RatingToAdd.DairyName);

            var ratingLabel = new Label()
            {
                Text = "Rating:"
            };
            var notesLabel = new Label()
            {
                Text = "Notes:"
            };


            var ratingView = new RatingView(true);

            ratingView.SetBinding(RatingView.WedgeRatingProperty, "RatingToAdd.WedgeRating");

            var notesEntry = new Entry()
            {
            };

            notesEntry.SetBinding(Entry.TextProperty, "RatingToAdd.Notes");

            var entryGrid = new Grid()
            {
                ColumnSpacing   = 0,
                RowSpacing      = 2,
                VerticalOptions = LayoutOptions.Start
            };

            entryGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            entryGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });

            entryGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = GridLength.Auto
            });
            entryGrid.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(1, GridUnitType.Star)
            });

            entryGrid.Children.Add(ratingLabel, 0, 0);
            entryGrid.Children.Add(ratingView, 1, 0);
            entryGrid.Children.Add(notesLabel, 0, 1);
            entryGrid.Children.Add(notesEntry, 1, 1);

            var saveButton = new Button()
            {
                Text            = "Save",
                FontAttributes  = FontAttributes.Bold,
                BackgroundColor = CheeseColors.RED,
                TextColor       = Color.White,
                FontSize        = 18,
                BorderRadius    = 0
            };

            saveButton.Command = _viewModel.AddRatingCommand;

            var cancelButton = new Button()
            {
                Text            = "Cancel",
                FontAttributes  = FontAttributes.Bold,
                BackgroundColor = CheeseColors.GRAY,
                TextColor       = Color.White,
                FontSize        = 18,
                BorderRadius    = 0
            };

            var grid = new Grid()
            {
                RowDefinitions = { new RowDefinition {
                                       Height = new GridLength(40, GridUnitType.Star)
                                   } },
                ColumnDefinitions =
                {
                    new ColumnDefinition()
                    {
                        Width = new GridLength(.5, GridUnitType.Star)
                    },
                    new ColumnDefinition()
                    {
                        Width = new GridLength(.5, GridUnitType.Star)
                    }
                },
                Padding       = new Thickness(0, 0, 0, 0),
                RowSpacing    = 0,
                ColumnSpacing = 0
            };

            grid.Children.Add(saveButton, 0, 0);
            grid.Children.Add(cancelButton, 1, 0);

            cancelButton.Clicked += async(sender, e) => {
                await Navigation.PopAsync(true);
            };

            var scroll = new ScrollView();

            scroll.Content = new StackLayout {
                Children =
                {
                    cheeseName,
                    dairyName,
                    entryGrid,
                    grid
                }
            };

            var headerImage = new Image {
                Source = "Header.png"
            };

            Content = new StackLayout()
            {
                Children =
                {
                    headerImage,
                    scroll
                }
            };
        }
コード例 #4
0
ファイル: AddRatingView.cs プロジェクト: codemillmatt/DevDays
        public AddRatingView(Cheese cheese)
        {
            _viewModel = new AddRatingViewModel (cheese, this);
            BindingContext = _viewModel;

            var cheeseName = new Label ();
            cheeseName.Text = string.Format ("The cheese name is {0}", _viewModel.RatingToAdd.CheeseName);

            var dairyName = new Label () { Text = "Dairy Name" };
            dairyName.Text = string.Format ("The dairy name is {0}", _viewModel.RatingToAdd.DairyName);

            var ratingLabel = new Label () { Text = "Rating:" };
            var notesLabel = new Label () { Text = "Notes:" };

            var ratingView = new RatingView (true);
            ratingView.SetBinding (RatingView.WedgeRatingProperty, "RatingToAdd.WedgeRating");

            var notesEntry = new Entry () { };
            notesEntry.SetBinding (Entry.TextProperty, "RatingToAdd.Notes");

            var entryGrid = new Grid () {
                ColumnSpacing = 0,
                RowSpacing = 2,
                VerticalOptions = LayoutOptions.Start
            };

            entryGrid.RowDefinitions.Add (new RowDefinition (){ Height = GridLength.Auto });
            entryGrid.RowDefinitions.Add (new RowDefinition () { Height = GridLength.Auto });

            entryGrid.ColumnDefinitions.Add (new ColumnDefinition () { Width = GridLength.Auto });
            entryGrid.ColumnDefinitions.Add (new ColumnDefinition (){ Width = new GridLength (1, GridUnitType.Star) });

            entryGrid.Children.Add (ratingLabel, 0, 0);
            entryGrid.Children.Add (ratingView, 1, 0);
            entryGrid.Children.Add (notesLabel, 0, 1);
            entryGrid.Children.Add (notesEntry, 1, 1);

            var saveButton = new Button () {
                Text = "Save",
                FontAttributes = FontAttributes.Bold,
                BackgroundColor = CheeseColors.RED,
                TextColor = Color.White,
                FontSize = 18,
                BorderRadius = 0
            };
            saveButton.Command = _viewModel.AddRatingCommand;

            var cancelButton = new Button () {
                Text = "Cancel",
                FontAttributes = FontAttributes.Bold,
                BackgroundColor = CheeseColors.GRAY,
                TextColor = Color.White,
                FontSize = 18,
                BorderRadius = 0
            };

            var grid = new Grid () {
                RowDefinitions = { new RowDefinition { Height = new GridLength (40, GridUnitType.Star) } },
                ColumnDefinitions = {
                    new ColumnDefinition () { Width = new GridLength (.5, GridUnitType.Star) },
                    new ColumnDefinition () { Width = new GridLength (.5, GridUnitType.Star) }
                },
                Padding = new Thickness (0, 0, 0, 0),
                RowSpacing = 0,
                ColumnSpacing = 0
            };

            grid.Children.Add (saveButton, 0, 0);
            grid.Children.Add (cancelButton, 1, 0);

            cancelButton.Clicked += async (sender, e) => {
                await Navigation.PopAsync(true);
            };

            var scroll = new ScrollView ();

            scroll.Content = new StackLayout {
                Children = {
                    cheeseName,
                    dairyName,
                    entryGrid,
                    grid
                }
            };

            var headerImage = new Image { Source = "Header.png" };

            Content = new StackLayout() {
                Children = {
                    headerImage,
                    scroll
                }
            };
        }
コード例 #5
0
		public async Task<Cheese> AddCheeseAsync (Cheese newCheese)
		{
			if (!_isInitialized)
				await InitializeDataStore();

			newCheese.CheeseId = Guid.NewGuid ().ToString ();

			await _sqliteConn.InsertAsync (newCheese).ConfigureAwait (false);

			return newCheese;
		}
コード例 #6
0
		public async Task<Cheese> AddCheeseAsync (Cheese newCheese)
		{
			if (!_isInitialized)
				await InitializeDataStore ();

			var cheeseSync = _client.GetSyncTable<Cheese> ();

			await cheeseSync.InsertAsync (newCheese);

			if (CrossConnectivity.Current.IsConnected) {
				await _client.SyncContext.PushAsync ();
			}

			return newCheese;
		}
コード例 #7
0
		public async Task<Cheese> AddCheeseAsync (Cheese newCheese)
		{
			if (!CrossConnectivity.Current.IsConnected)
				throw new NoInternetException();

			if (!_isInitialized)
				await InitializeDataStore ();

			await _client.GetTable<Cheese> ().InsertAsync (newCheese).ConfigureAwait (false);

			return newCheese;
		}