public IEnumerable<Category> GetAll()
        {
            List<Category> categories = new List<Category>();

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

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                var dbCategories = dataContext.Categories;

                foreach (var dbCategory in dbCategories)
                {
                    Category category =
                        new Category()
                        {
                            Id = dbCategory.Id,
                            Name = dbCategory.Name
                        };

                    categories.Add(category);
                }
            }

            return categories;
        }
        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();
            }
        }
        public void Insert(Category category)
        {
            CategoryLinqEntity categoryLinq = new CategoryLinqEntity()
            {
                Name = category.Name
            };

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

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                dataContext.Categories.InsertOnSubmit(categoryLinq);

                dataContext.SubmitChanges();
            }
        }
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

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

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                if (!dataContext.DatabaseExists())
                {
                    dataContext.CreateDatabase();
                }
            }

            JourneyRepository repo = new JourneyRepository();

            var readJourneys = repo.GetAll();
        }
        public void DeleteOlderThan(DateTime date)
        {
            string connectionString = "Data Source=isostore:/MileageTracker.sdf";

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                IEnumerable<JourneyLinqEntity> dbJourneys =
                    dataContext.Journeys
                        .Where(j => j.Date < date);

                foreach (var dbJourney in dbJourneys)
                {
                    dataContext.Journeys.DeleteOnSubmit(dbJourney);
                }

                dataContext.SubmitChanges();
            }
        }
        public Category GetById(int id)
        {
            Category category;

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

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                CategoryLinqEntity dbCategory =
                    dataContext.Categories
                        .Where(j => j.Id == id)
                        .Single();

                // TODO: Make data adapter or use automapper?
                category = new Category()
                {
                    Id = dbCategory.Id,
                    Name = dbCategory.Name
                };
            }

            return category;
        }
        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 Update(Category category)
        {
            string connectionString = "Data Source=isostore:/MileageTracker.sdf";

            using (LinqDataContext dataContext = new LinqDataContext(connectionString))
            {
                CategoryLinqEntity dbCategory =
                    dataContext.Categories
                        .Where(c => c.Id == category.Id)
                        .Single();

                dbCategory.Name = category.Name;

                dataContext.SubmitChanges();
            }
        }