Exemplo n.º 1
0
        private void RefreshStops()
        {
            if (_vmStops == null)
            {
                _vmStops = new StopsViewModel(_routeName, _flStops, _flStopsPending);
                StopsListBox.DataContext           = _vmStops;
                StopPanel.DataContext              = _vmStops;
                stopAttributesDataGrid.DataContext = _vmStops;
            }

            LookupFieldNames();
            if (_stopsRouteNameFieldName == null)
            {
                return;
            }

            string where = "1=1";
            if (!String.IsNullOrWhiteSpace(_routeName))
            {
                where = (_stopsRouteNameFieldName + "='" + _routeName + "'");
            }

            _vmStops.Update(_flStops, where);

            BindSelectedStop(false);
        }
Exemplo n.º 2
0
        public StopsPage(Route route)
        {
            InitializeComponent();

            BindingContext = this._viewModel = new StopsViewModel(route, StkDir);
            _viewModel.ChangeDirection(route.Directions.FirstOrDefault());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Post(string tripName, [FromBody] StopsViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var newStop = Mapper.Map <Stop>(vm);

                    var result = await _coordService.GetCoordAsync(newStop.Name);

                    if (!result.Success)
                    {
                        _logger.LogError(result.Message);
                    }
                    else
                    {
                        newStop.Latitude  = result.Latitude;
                        newStop.Longitude = result.Longitude;
                    }

                    _repository.AddStop(tripName, newStop, User.Identity.Name);

                    if (await _repository.SaveChangesAsync())
                    {
                        return(Created($"/api/trips/{tripName}/stops/{newStop.Name}", Mapper.Map <StopsViewModel>(newStop)));
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to save new Stop {0}", ex);
            }

            return(BadRequest("Failed to save new Stop "));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Post([FromBody] StopsViewModel stopVM, string tripName)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var stop = Mapper.Map <Stop>(stopVM);

                    //longitude i latitude
                    var location = await _service.DetermineLocation(stop);

                    if (!location.Result)
                    {
                        _logger.LogError("could not determine long/lat");
                    }
                    else
                    {
                        stop.Latitude  = location.Latitude;
                        stop.Longitude = location.Longitude;

                        _repository.AddStopToTrip(stop, tripName, User.Identity.Name);
                        if (await _repository.SaveChangesAsync())
                        {
                            return(Created($"api/trips/{tripName}/stops/{stop.Name}", Mapper.Map <StopsViewModel>(stop)));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error saving stop: {ex}");
            }
            return(BadRequest("Error saving stop"));
        }
 public IActionResult Edit(int id, StopsViewModel stop)
 {
     if (stop != null && ModelState.IsValid)
     {
         _context.UpdateStopById(id, stop);
         return(RedirectToAction("Details", new { id = id }));
     }
     return(View(stop));
 }
        public IActionResult New()
        {
            StopsViewModel stop = new StopsViewModel();

            stop.trailList = _context.GetAllTrailsSelectListItem();
            stop.admin_id  = 1; ///////////////////////////////////////////////////////test

            return(View(stop));
        }
Exemplo n.º 7
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo info)
        {
            // value to Visibility
            StopsViewModel vm = value as StopsViewModel;

            if (vm == null)
            {
                return(Visibility.Collapsed);
            }

            // TODO - add cases for Visibility.Collapsed

            return(Visibility.Visible);
        }
        public IActionResult Details(int?id)
        {
            StopsViewModel stop = new StopsViewModel();

            if (id.HasValue)
            {
                stop = _context.GetStopById(id);
                if (stop == null)
                {
                    stop = new StopsViewModel();
                }
                return(View("Details", stop));
            }
            return(View("Details", stop));
        }
        public IActionResult Edit(int?id)
        {
            StopsViewModel stop = new StopsViewModel();

            stop.trailList = _context.GetAllTrailsSelectListItem();

            if (id.HasValue)
            {
                stop = _context.GetStopById(id);
                if (stop == null)
                {
                    stop = new StopsViewModel();
                }
                return(View("Edit", stop));
            }
            return(View("Edit", stop));
        }
 public IActionResult New(StopsViewModel stop)
 {
     stop.trailList = _context.GetAllTrailsSelectListItem();
     if (stop != null && ModelState.IsValid)
     {
         string msg = _context.InsertStop(stop);
         // If new data is successfully inserted,
         if (msg == "Insert")
         {
             return(View("details", stop));
         }
         else
         {
             return(View(stop));
         }
     }
     return(View(stop));
 }
Exemplo n.º 11
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo info)
        {
            // value to Visibility
            StopsViewModel vm = value as StopsViewModel;

            if (vm == null)
            {
                return(Visibility.Collapsed);
            }

            Stop stop = vm.SelectedItem as Stop;

            if (stop == null)
            {
                return(Visibility.Collapsed);
            }

            return(stop.IsBreak ? Visibility.Visible : Visibility.Collapsed);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Get(string tripsName, [FromBody] StopsViewModel stopsViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Model Not Valid In post"));
                }

                var newStop = Mapper.Map <Stop>(stopsViewModel);

                var result = await _coordsService.GetCoordsAsync(newStop.Name);

                if (!result.Success)
                {
                    _logger.LogError(result.Message);
                }
                else
                {
                    newStop.Latitude  = result.Latitude;
                    newStop.Longitude = result.Longitude;

                    _repository.AddStops(tripsName, newStop);

                    if (await _repository.SaveChangesAsync())
                    {
                        return(Created($"api/trips/{tripsName}/stops/{newStop.Name}",
                                       Mapper.Map <StopsViewModel>(newStop)));
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError("Failed to Save Stop:{0}", e);
            }
            return(BadRequest("Failed To save New Stop"));
        }
Exemplo n.º 13
0
        public StopsPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new StopsViewModel();
        }