Ejemplo n.º 1
0
        public SearchAddressViewModel()
        {
            stopService = (App.Current as App).Container.GetService <IStopService>();

            // New up our observable collection
            AddressesFound = new ObservableCollection <StringWrapper>();

            SearchCommand = new RelayCommand(async() =>
            {
                // If our button is showing "search", let's do the following
                if (SearchAddButtonText == "Search")
                {
                    // Reset everything
                    AddressesFound.Clear();
                    AddressSelected = new StringWrapper();

                    MapLocationFinderResult result = await
                                                     MapLocationFinder.FindLocationsAsync(BuildingNumber + " " + StreetName + ", " + PostCode, null);

                    if (result.Status == MapLocationFinderStatus.Success)
                    {
                        MapAddress address = result.Locations.FirstOrDefault().Address;
                        Geopoint point     = result.Locations.FirstOrDefault().Point;
                        var stringw        = new StringWrapper
                        {
                            StringContent = address.FormattedAddress,
                            TempLatitude  = Convert.ToDecimal(point.Position.Latitude),
                            TempLongitude = Convert.ToDecimal(point.Position.Longitude)
                        };
                        AddressesFound.Add(stringw);
                    }
                    else
                    {
                        return;
                    }
                }
                else // it's basically showing "Add" at this point, so add our item to the list of stops
                {
                    StopModel stopModel = new StopModel()
                    {
                        Name     = StopName, Address = AddressSelected.StringContent,
                        Latitude = AddressSelected.TempLatitude, Longitude = AddressSelected.TempLongitude
                    };
                    stopService.AddStop(stopModel);
                }
            });
        }
Ejemplo n.º 2
0
        public IActionResult AddStop(CreatedStop createdStop)
        {
            if (createdStop.DepartureTime > createdStop.ArrivalTime)
            {
                return(BadRequest());
            }
            TimeSpan duration = createdStop.ArrivalTime - createdStop.DepartureTime;

            createdStop.Duration = duration.TotalSeconds;
            int  idOfNewElement = _stops.AddStop(createdStop);
            Stop stop           = createdStop.ToStop();

            stop.StopId = idOfNewElement;

            stop.Duration = duration.TotalSeconds;

            return(Created(HttpContext.Request.Scheme + "//" + HttpContext.Request.Host + HttpContext.Request.Path + "/" + idOfNewElement, stop));
        }