Beispiel #1
0
 public MountainViewModel(MountainDbData dbData)
     : this()
 {
     id          = dbData.Id;
     neLat       = dbData.NeLat;
     neLng       = dbData.NeLng;
     swLat       = dbData.SwLat;
     swLng       = dbData.SwLng;
     title       = dbData.Title;
     description = dbData.Description;
 }
Beispiel #2
0
        private void RequestHeight(MountainDbData mountain, MountainDbContext context)
        {
            var request = new HeightRequestDbData
            {
                MountainId    = mountain.Id,
                NeLat         = mountain.NeLat,
                NeLng         = mountain.NeLng,
                SwLat         = mountain.SwLat,
                SwLng         = mountain.SwLng,
                RequestNumber = 0,
                ResolutionX   = 100,
                ResolutionY   = 100
            };

            context.HeightRequests.Add(request);
            context.SaveChanges();
        }
Beispiel #3
0
        private MountainDbData Save(MountainViewModel vm, MountainDbContext context)
        {
            var mountain       = context.Mountains.FirstOrDefault(i => i.Id == vm.id);
            var isNewMountain  = (mountain == null);
            var isDataOutdated = false;

            if (isNewMountain)
            {
                mountain = new MountainDbData();
            }

            mountain.Title       = vm.title;
            mountain.Description = vm.description;

            if (mountain.NeLat != vm.neLat || mountain.NeLng != vm.neLng ||
                mountain.SwLat != vm.swLat || mountain.SwLng != vm.swLng)
            {
                isDataOutdated = true;
            }

            mountain.NeLat = vm.neLat;
            mountain.NeLng = vm.neLng;
            mountain.SwLat = vm.swLat;
            mountain.SwLng = vm.swLng;

            mountain.PreviewData = DataConverter.ConvertDataToString(
                new MountainData
            {
                Points     = vm.previewHeights,
                SplitRange = vm.preview
            });

            if (isDataOutdated)
            {
                mountain.OriginalData = null;
                mountain.GCodeData    = null;
            }

            if (isNewMountain)
            {
                context.Mountains.Add(mountain);
            }
            context.SaveChanges();
            return(mountain);
        }
Beispiel #4
0
        public async Task CreateDatabaseAndAddMountain()
        {
            using (var db = new MountainDbContext("MountainDBTestConnectionString"))
            {
                var mountain = new MountainDbData
                {
                    NeLat       = 3,
                    Title       = "Everest",
                    Description = "Highest mountain in the world!"
                };
                db.Mountains.Add(mountain);
                db.SaveChanges();

                Assert.AreEqual(1, await db.Mountains.CountAsync());

                db.Mountains.Remove(mountain);
                db.SaveChanges();

                Assert.AreEqual(0, await db.Mountains.CountAsync());
            }
        }
Beispiel #5
0
        public MountainViewModel GetMountainData(MountainDbData mountain)
        {
            if (mountain == null)
            {
                throw new Exception("Mountain not found");
            }

            var previewData  = DataConverter.ConvertStringToData(mountain.PreviewData);
            var originalData = DataConverter.ConvertStringToData(mountain.OriginalData);
            var viewModel    = new MountainViewModel(mountain);

            viewModel.resolution = originalData?.SplitRange ?? new SplitRange {
                x = 100, y = 100
            };
            viewModel.detailsHeights = originalData?.Points;
            viewModel.previewHeights = previewData?.Points;
            viewModel.preview        = previewData?.SplitRange ?? new SplitRange {
                x = 5, y = 100
            };
            viewModel.MountainData = originalData;
            return(viewModel);
        }