public IEnumerable<Journey> GetAll()
        {
            List<Journey> journeys = new List<Journey>();

            string connectionString = "Data Source=isostore:/MileageTracker.sdf";

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                var dbJourneys = dataContext.Journeys;

                foreach (var dbJourney in dbJourneys)
                {
                    Journey journey =
                        new Journey()
                        {
                            Id = dbJourney.Id,
                            Date = dbJourney.Date,
                            StartMileage = dbJourney.StartMileage,
                            EndMileage = dbJourney.EndMileage
                        };

                    journeys.Add(journey);
                }
            }

            return journeys;
        }
        public void Delete(Journey journey)
        {
            string connectionString = "Data Source=isostore:/MileageTracker.sdf";

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                JourneyLinqEntity dbJourney =
                    dataContext.Journeys
                        .Where(j => j.Id == journey.Id)
                        .Single();

                dataContext.Journeys.DeleteOnSubmit(dbJourney);

                dataContext.SubmitChanges();
            }
        }
        private void ApplicationBarIconButton_Save_Click(object sender, EventArgs e)
        {
            // TODO: Verify input, to ensure we have start mileage, end mileage and a date.
            Journey journey = new Journey()
            {
                Date = this.Date.Value.Value,
                StartMileage = int.Parse(this.StartMileage.Text),
                EndMileage = int.Parse(this.EndMileage.Text)
            };

            JourneyRepository journeyRepository = new JourneyRepository();

            journeyRepository.Insert(journey);

            App.ViewModel.LoadData();

            NavigationService.GoBack();
        }
        public Journey GetById(int id)
        {
            Journey journey;

            string connectionString = "Data Source=isostore:/MileageTracker.sdf";

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                JourneyLinqEntity dbJourney =
                    dataContext.Journeys
                        .Where(j => j.Id == id)
                        .Single();

                // TODO: Make data adapter or use automapper?
                journey = new Journey()
                {
                    Id = dbJourney.Id,
                    Date = dbJourney.Date,
                    StartMileage = dbJourney.StartMileage,
                    EndMileage = dbJourney.EndMileage
                };
            }

            return journey;
        }
        public void Insert(Journey journey)
        {
            JourneyLinqEntity journeyLinq = new JourneyLinqEntity()
            {
                Date = journey.Date,
                StartMileage = journey.StartMileage,
                EndMileage = journey.EndMileage
            };

            string connectionString = "Data Source=isostore:/MileageTracker.sdf";

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                dataContext.Journeys.InsertOnSubmit(journeyLinq);

                dataContext.SubmitChanges();
            }
        }
 public void LogJourney(Journey journey)
 {
     this.journeys.Add(journey);
 }