Exemplo n.º 1
0
        public async Task <IActionResult> Upsert(int?Id)
        {
            var nationalParksList = await _nationalPark.GetAllAsync(StaticDetails.NationalParkApiUrl);

            TrailViewModel trailViewModel = new TrailViewModel()
            {
                NationalParks = nationalParksList.Select(i => new SelectListItem
                {
                    Text  = i.Name,
                    Value = i.Id.ToString()
                }),
                Trail = new Trail()
            };

            if (Id == null)
            {
                return(View(trailViewModel));
            }
            trailViewModel.Trail = await _trailRepository.GetAsync(StaticDetails.TrailsApiUrl, Id.GetValueOrDefault());

            if (trailViewModel.Trail == null)
            {
                return(NotFound());
            }
            return(View(trailViewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Upsert(TrailViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Trail.Id == 0)
                {
                    await _trailRepository.CreateAsync(StaticDetails.TrailsApiUrl, model.Trail);
                }
                else
                {
                    await _trailRepository.UpdateAsync(StaticDetails.TrailsApiUrl + model.Trail.Id, model.Trail);
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                var nationalParksList = await _nationalPark.GetAllAsync(StaticDetails.NationalParkApiUrl);

                TrailViewModel trailViewModel = new TrailViewModel()
                {
                    NationalParks = nationalParksList.Select(i => new SelectListItem
                    {
                        Text  = i.Name,
                        Value = i.Id.ToString()
                    }),
                    Trail = model.Trail
                };
                return(View(trailViewModel));
            }
        }
 public MapPage(TrailViewModel trailViewModel)
 {
     InitializeComponent();
     trail         = trailViewModel;
     mapView.Map   = CreateMap();
     mapView.Info += StopInfo;
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Upsert(TrailViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var nationalParks = await _nationalParkRepository.GetAll(AppConstants.NationalParkApiPath);

                viewModel.NationalParks = nationalParks.Select(p => new SelectListItem()
                {
                    Text  = p.Name,
                    Value = p.Id.ToString()
                });

                return(View(viewModel));
            }

            if (viewModel.Trail.Id == 0)
            {
                await _trailRepository.CreateAsync(AppConstants.TrailsApiPath, viewModel.Trail);
            }
            else
            {
                await _trailRepository.UpdateAsync(AppConstants.TrailsApiPath, viewModel.Trail.Id, viewModel.Trail);
            }

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 5
0
        private TrailViewModel InitModel(string id = "")
        {
            var model = new TrailViewModel();

            if (!String.IsNullOrWhiteSpace(id))
            {
                // load the trail
                var trail = _topoTrailService.GetTrail(id);
                model.Trail  = trail;
                model.Tracks = trail.TopoTracks;

                // search for elevation data
                var elevation = _demElevationService.GetElevationData(trail);
                if (elevation.OK)
                {
                    // add data if available
                    model.Elevation = elevation.Data;
                }
                else
                {
                    // show error message
                    model.ErrorMessages.Add(elevation.Message);
                }

                // search for health data
                model.Training = _bioHealthService.GetTrainingInfo(trail.StartLocal, trail.FinishLocal);
            }

            return(model);
        }
        public IActionResult New()
        {
            TrailViewModel trail = new TrailViewModel();

            trail = _context.getColorCodeList(trail);

            return(View(trail));
        }
 public IActionResult Edit(int id, TrailViewModel trail)
 {
     if (trail != null && ModelState.IsValid)
     {
         _context.UpdateTrailById(id, trail);
         return(RedirectToAction("Details", new { id = id }));
     }
     return(View(trail));
 }
Exemplo n.º 8
0
        public TrailPage(TrailViewModel trailViewModel)
        {
            InitializeComponent();
            this.trailViewModel = trailViewModel;
            BindingContext      = trailViewModel;
            ISimpleAudioPlayer player     = CrossSimpleAudioPlayer.Current;
            WebClient          wc         = new WebClient();
            Stream             fileStream = wc.OpenRead(trailViewModel.AudioUri);

            player.Load(fileStream);
        }
        public IActionResult Edit(int?id)
        {
            TrailViewModel trail = new TrailViewModel();

            if (id.HasValue)
            {
                trail = _context.GetTrailById(id, trail);
                trail = _context.getColorCodeList(trail);
                //if (trail == null)
                //{
                //    trail = new TrailViewModel();
                //}
                return(View("Edit", trail));
            }
            return(View("Edit", trail));
        }
Exemplo n.º 10
0
        public IHttpActionResult Post(TrailViewModel trail)
        {
            Trail dbtrail = new Trail()
            {
                Trailnumber = trail.Trailnumber,
                Name        = trail.Name,
                Status      = trail.Status,
                Time        = trail.Time,
                UserId      = User.Identity.GetUserId()
            };

            _db.Trails.Add(dbtrail);

            _db.SaveChanges();

            return(Ok(trail));
        }
 public IActionResult New(TrailViewModel trail)
 {
     if (trail != null && ModelState.IsValid)
     {
         string msg = _context.InsertTrail(trail);
         // If new data is successfully inserted,
         if (msg == "Insert")
         {
             return(View("details", trail));
         }
         else
         {
             return(View(trail));
         }
     }
     return(View(trail));
 }
Exemplo n.º 12
0
 public IActionResult Add(TrailViewModel newTrail)
 {
     if (ModelState.IsValid)
     {
         Trail trail = new Trail {
             Name        = newTrail.Name,
             Description = newTrail.Description,
             Length      = newTrail.Length,
             Elevation   = newTrail.Elevation,
             Latitude    = newTrail.Latitude,
             Longitude   = newTrail.Longitude
         };
         trailFactory.Add(trail);
         return(RedirectToAction("Index"));
     }
     return(View("NewTrail"));
 }
Exemplo n.º 13
0
 public IActionResult AddTrail(TrailViewModel model)
 {
     if (ModelState.IsValid)
     {
         var Trail = new Trail {
             name        = model.name,
             length      = model.length,
             elev_change = model.elev_change,
             longitude   = model.longitude,
             latitude    = model.latitude,
             description = model.description,
         };
         trailFactory.Add(Trail);
         return(RedirectToAction("Index"));
     }
     return(View("AddForm", model));
 }
Exemplo n.º 14
0
 public IActionResult Create(TrailViewModel model)
 {
     if (ModelState.IsValid)
     {
         Trail newTrail = new Trail
         {
             Name        = model.Name,
             Description = model.Description,
             Length      = model.Length,
             Elevation   = model.Elevation,
             Longitude   = model.Longitude,
             Latitude    = model.Latitude,
         };
         _trailfactory.AddNewTrail(newTrail);
     }
     else
     {
         // ViewBag.errors = ModelState.Values;
         return(View("New"));
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 15
0
        public async Task <IActionResult> Upsert(int?id)
        {
            var nationalParks = await _nationalParkRepository.GetAll(AppConstants.NationalParkApiPath);

            var viewModel = new TrailViewModel()
            {
                NationalParks = nationalParks.Select(p => new SelectListItem()
                {
                    Text  = p.Name,
                    Value = p.Id.ToString()
                }),
                Trail = new Trail()
            };

            if (!id.HasValue)
            {
                return(View(viewModel));
            }

            viewModel.Trail = await _trailRepository.GetById(AppConstants.TrailsApiPath, id.Value);

            return(View(viewModel));
        }
Exemplo n.º 16
0
 public StopList(TrailViewModel trailViewModel)
 {
     InitializeComponent();
     BindingContext = trailViewModel;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Clears the current trail data edit session
        /// </summary>
        public ActionResult Discard()
        {
            _editing = null;

            return(Redirect(TrailViewModel.GetImportUrl()));
        }