Пример #1
0
        public IActionResult Index()
        {
            vmLocation myVM = new vmLocation();

            var gt = _CurrentUserGooToken();

            if (gt != null)
            {
                using (GoogleService service = new GoogleService(gt))
                {
                    foreach (var item in service.getCalendars().Items)
                    {
                        myVM.GoogleCalendars.Add(item.Id, item.Summary);
                    }
                }
            }
            myVM.Token = _GetToken();
            return(View(myVM));
        }
Пример #2
0
        /// <summary>
        /// Store the selected location to the collection of locations.
        /// Do not store if the name and the position < 3 km of a location already present
        /// </summary>
        public void StoreLocation()
        {
            if (this.Location == _ConstUnknownLocation)
            {
                return;
            }
            if (GeoPosition == null)
            {
                return;
            }

            foreach (vmLocation Location in Locations)
            {
                if (Location.Name == this.Location)
                {
                    double Distance = (CalculateDistance(Location.Latitude,
                                                         Location.Longitude,
                                                         GeoPosition.Coordinate.Point.Position.Latitude,
                                                         GeoPosition.Coordinate.Point.Position.Longitude));

                    if (Distance < 2000) //A location with the samen name within two kilometers is considered the same
                    {
                        return;
                    }
                }
            }

            vmLocation newLocation = new vmLocation();

            newLocation.Name      = this.Location;
            newLocation.Latitude  = GeoPosition.Coordinate.Point.Position.Latitude;
            newLocation.Longitude = GeoPosition.Coordinate.Point.Position.Longitude;
            newLocation.SetNameAndLocation(GeoPosition);
            Locations.Add(newLocation);

            UpdateNearbyLocations();
        }
Пример #3
0
        public IActionResult Location(long id)
        {
            try
            {
                vmLocation myVM = new vmLocation();
                myVM.Location = _context.Locations.Include(s => s.Schedule).FirstOrDefault(x => x.Id == id);

                if (myVM.Location != null)
                {
                    //fill google calendars

                    var gt = _CurrentUserGooToken();
                    if (gt != null)
                    {
                        using (GoogleService service = new GoogleService(gt))
                        {
                            foreach (var item in service.getCalendars().Items)
                            {
                                myVM.GoogleCalendars.Add(item.Id, item.Summary);
                            }
                        }
                    }
                    myVM.Token = _GetToken();
                    return(View(myVM));
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error /location/{id}");
                throw;
            }
        }