Ejemplo n.º 1
0
        public TripDetailPage(TripLogEntry tripLogEntry)
        {
            BindingContext = new DetailViewModel(tripLogEntry);
            InitializeComponent();

            LoadData();
        }
Ejemplo n.º 2
0
        public async Task RemoveEntryAsync(TripLogEntry entry) //Remove
        {
            //url = "http://<service-name>.azurewebsites.net" + "/tables/entry/entry.id"
            var url = new Uri(_baseUri, $"/tables/entry/{entry.Id}");

            var response = await SendRequestAsync <TripLogEntry>(url, HttpMethod.Delete, _headers);
        }
        async Task ExecuteSaveCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var newItem = new TripLogEntry
                {
                    Title     = Title,
                    Latitude  = Latitude,
                    Longitude = Longitude,
                    Date      = Date,
                    Rating    = Rating,
                    Notes     = Notes
                };

                await _tripLogService.AddEntryAsync(newItem);

                await NavService.GoBack();
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 4
0
        private async Task executeSaveCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            var newItem = new TripLogEntry
            {
                Title     = this.Title,
                Latitude  = this.Latitude,
                Longitude = this.Longitude,
                Date      = this.Date,
                Rating    = this.Rating,
                Notes     = this.Notes
            };

            try
            {
                await _tripLogService.AddEntryAsync(newItem);

                await NavService.GoBack();
            }
            finally {
                IsBusy = false;
            }
        }
Ejemplo n.º 5
0
 public async Task RemoveEntryAsync(TripLogEntry entry)
 {
     var url = new Uri(_baseUri,
                       string.Format("/api/TripLogEntry/{0}", entry.Id));
     var response = await SendRequestAsync <TripLogEntry>(url,
                                                          HttpMethod.Delete, _headers);
 }
Ejemplo n.º 6
0
        async Task ExecuteSaveCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var newItem = new TripLogEntry
                {
                    Title     = Title,
                    Latitude  = Latitude,
                    Longitude = Longitude,
                    Date      = Date,
                    Rating    = Rating,
                    Notes     = Notes
                };

                // TODO: Persist Entry in a later chapter.

                // TODO: Remove this in Chapter 6
                await Task.Delay(3000);

                await NavService.GoBack();
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 7
0
        public async Task <TripLogEntry> AddEntryAsync(TripLogEntry entry)
        {
            var url      = new Uri(_baseUri, "/tables/entry");
            var response = await SendRequestAsync <TripLogEntry>(url, HttpMethod.Post, _headers, entry);

            return(response);
        }
        public void Delete_StoresMany_Then_DeletesExisting_RetrievesRemainingEntries()
        {
            // Arrange
            var entry1 = new TripLogEntry()
            {
                Title = "Title1"
            };
            var entry2 = new TripLogEntry()
            {
                Title = "Title2"
            };
            var entry3 = new TripLogEntry()
            {
                Title = "Title3"
            };

            testee.Store(entry1);
            testee.Store(entry2);
            testee.Store(entry3);

            // Act
            var result = testee.Delete(entry2);

            // Assert
            Assert.IsTrue(result);
            var reminingEntries = testee.Retrieve().ToList();

            Assert.AreEqual(reminingEntries.Count(), 2);
            Assert.IsFalse(reminingEntries.Contains(entry2));
        }
Ejemplo n.º 9
0
        public async Task <TripLogEntry> UpdateEntryAsync(TripLogEntry entry)
        {
            var url      = new Uri(_baseUri, string.Format("/tables/entry/{0}", entry.Id));
            var response = await SendRequestAsync <TripLogEntry>(url, new HttpMethod("PATCH"), _headers, entry);

            return(response);
        }
Ejemplo n.º 10
0
        private async Task Save()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                /**/
                var newItem = new TripLogEntry
                {
                    Title     = Title,
                    Latitude  = Latitude,
                    Longitude = Longitude,
                    Date      = Date,
                    Rating    = Rating,
                    Notes     = Notes
                };

                // TODO: Persist entry

                await Task.Delay(3000);

                await NavService.GoBack();
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 11
0
        public DetailPage(TripLogEntry entry)
        {
            InitializeComponent();

            try
            {
                map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(entry.Latitude, entry.Longitude), Distance.FromMiles(.5)));

                map.Pins.Add(new Pin
                {
                    Type     = PinType.Place,
                    Label    = entry.Title,
                    Position = new Position(entry.Latitude, entry.Longitude)
                });

                title.Text  = entry.Title;
                date.Text   = entry.Date.ToString("M");
                rating.Text = $"{entry.Rating} star rating";
                notes.Text  = entry.Notes;
            }
            catch
            {
                DisplayAlert("Cannot Connect", "I noticed that at the moment it works on iOS but not Android.", "Ok");
            }
        }
Ejemplo n.º 12
0
        async Task ExecuteSaveCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var newItem = new TripLogEntry
                {
                    Title     = Title,
                    Latitude  = Latitude,
                    Longitude = Longitude,
                    Date      = Date,
                    Rating    = Rating,
                    Notes     = Notes
                };

                //Azure Data Access: Add new entry to Azure database
                await _tripLogDataService.AddEntryAsync(newItem);

                //Navigation Service : Go back to the main page
                await NavService.GoBack();
            }
            finally
            {
                IsBusy = false;
            }
        }
 public void Add(TripLogEntry value)
 {
     using (var transaction = Db.GetTransaction())
     {
         transaction.Insert(TableName, value.Id, Serialize(value));
         transaction.Commit();
     }
 }
Ejemplo n.º 14
0
        private void trips_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            TripLogEntry trip = (TripLogEntry)e.Item;

            Navigation.PushAsync(new DetailPage());

            trips.SelectedItem = null;
        }
Ejemplo n.º 15
0
        public void MainViewModelInitializationThrowsTest()
        {
            var viewModel = new MainViewModel(TestInit.MockedTripLogDataService.Object);

            var entry = new TripLogEntry();

            viewModel.Init(entry);
        }
Ejemplo n.º 16
0
        public async Task NewEntryViewModelInitializationThrowsTest()
        {
            var viewModel = new NewEntryViewModel(TestInit.MockedGeoLocationService.Object, TestInit.MockedTripLogDataService.Object);

            var entry = new TripLogEntry();

            await viewModel.Init(entry);
        }
Ejemplo n.º 17
0
        public async Task <TripLogEntry> UpdateEntryAsync(TripLogEntry entry) //Update
        {
            //url = "http://<service-name>.azurewebsites.net" + "/tables/entry/entry.id"
            var url = new Uri(_baseUri, $"/tables/entry/{entry.Id}");

            var response = await SendRequestAsync <TripLogEntry>(url, new HttpMethod("PATCH"), _headers, entry);

            return(response);
        }
Ejemplo n.º 18
0
        public ContentPage Build(ViewType modelType, TripLogEntry entry)
        {
            var viewModel = _viewModelFactory.Build(modelType);

            viewModel.Init(entry);
            var view = _viewFactory.Build(modelType, viewModel);

            return(view);
        }
Ejemplo n.º 19
0
        public async Task <TripLogEntry> AddEntryAsync(TripLogEntry entry)
        {
            var entryJson = JsonConvert.SerializeObject(entry);
            var result    = await firebase
                            .Child("TripLogs")
                            .PostAsync(entryJson);

            return(entry);
        }
Ejemplo n.º 20
0
        public Task NavigateToDetailPage(TripLogEntry entry)
        {
            var vm = this.viewModelFactory.BuildDetailPageViewModel();

            vm.Init(entry);
            var page = this.viewFactory.BuildDetailPage(vm);

            return(navigation.PushAsync(page));
        }
Ejemplo n.º 21
0
        public async Task <TripLogEntry> AddEntryAsync(TripLogEntry entry) //Add
        {
            //url = "http://<service-name>.azurewebsites.net" + "/tables/entry"
            var url = new Uri(_baseUri, "/tables/entry");

            var response = await SendRequestAsync <TripLogEntry>(url, HttpMethod.Post, _headers, entry);

            return(response);
        }
Ejemplo n.º 22
0
        public async Task DetailViewModelInitializationThrowsTest()
        {
            var viewModel = new DetailViewModel();

            var entry = new TripLogEntry();

            await viewModel.Init(entry);

            Assert.AreEqual(entry, viewModel.Entry);
        }
Ejemplo n.º 23
0
 public int DeleteItem(TripLogEntry entry)
 {
     if (entry._id != 0)
     {
         lock (locker)
         {
             return(_database.Delete <TripLogEntry>(entry._id));
         }
     }
     return(entry._id);
 }
Ejemplo n.º 24
0
        private async void trips_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TripLogEntry entry = e.CurrentSelection.FirstOrDefault() as TripLogEntry;

            if (entry != null)
            {
                await Navigation.PushAsync(new DetailPage(entry));
            }

            // Clear selection after
            trips.SelectedItem = null;
        }
Ejemplo n.º 25
0
 void ExecuteSaveCommand()
 {
     var newItem = new TripLogEntry
     {
         Title     = Title,
         Latitude  = Latitude,
         Longitude = Longitude,
         Date      = Date,
         Rating    = Rating,
         Notes     = Notes
     };
 }
Ejemplo n.º 26
0
        public async Task <TripLogEntry> UpdateEntryAsync(TripLogEntry entry)
        {
            var entryJson       = JsonConvert.SerializeObject(entry);
            var toUpdateTripLog = (await firebase
                                   .Child("TripLogs")
                                   .OnceAsync <TripLogEntry>()).Where(item => item.Object.Id == entry.Id).FirstOrDefault();

            await firebase
            .Child("TripLogs/" + entry.Id)
            .PutAsync(entryJson);

            return(entry);
        }
Ejemplo n.º 27
0
        public void AddSameElementTwiceToPersistencyTest()
        {
            var title1 = "Number1";
            var entry  = new TripLogEntry(title1);

            _db.Add(entry);
            _db.Add(entry);

            var allEntries = _db.GetAll();

            Assert.AreEqual(1, allEntries.Count());
            Assert.AreEqual(1, allEntries.Count(elem => elem.Title.Equals(title1)));
        }
Ejemplo n.º 28
0
        public ActionResult <TripLogEntry> Post(TripLogEntry entry)
        {
            try
            {
                _persistency.Store(entry);

                return(CreatedAtAction(nameof(Post), new { id = entry.Title }, entry));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e?.Message));
            }
        }
        public IEnumerable <TripLogEntry> GetAll()
        {
            IList <TripLogEntry> result;

            using (var transaction = Db.GetTransaction())
            {
                var select = transaction.SelectForward <string, string>(TableName);
                result = select.Select(elem => TripLogEntry.Deserialize(elem.Value)).ToList();
                transaction.Commit();
            }

            return(result);
        }
Ejemplo n.º 30
0
        public IHttpActionResult Post([FromBody] TripLogEntry value)
        {
            try
            {
                _persistency.Add(value);
                _persistency.Dispose();

                return(CreatedAtRoute("DefaultApi", new { id = value.Id }, value));
            }
            catch (Exception e)
            {
                return(ThrowHttpResponseException(e));
            }
        }