//For the Fire Station Points
        public static Task UpdateFireStationLocations(List <FireStationServicesDTO> fireStations)
        {
            DataModel db = new DataModel();
            List <PointsOfInterest> pointsOfInterests = db.PointsOfInterest.ToList();

            foreach (var fireStation in fireStations)
            {
                PointsOfInterest existingPointsOfInterest =
                    pointsOfInterests.FirstOrDefault(x => x.Name == fireStation.Name);

                if (existingPointsOfInterest == null)
                {
                    PointsOfInterest pointsOfInterestModel = new PointsOfInterest();
                    pointsOfInterestModel.Name      = fireStation.Name;
                    pointsOfInterestModel.Latitude  = fireStation.Location.Coordinates[1].ToString();
                    pointsOfInterestModel.Longitude = fireStation.Location.Coordinates[0].ToString();
                    pointsOfInterestModel.Type      = "Fire Station";

                    var latLongLocation = new Loc(Convert.ToDouble(pointsOfInterestModel.Latitude), Convert.ToDouble(pointsOfInterestModel.Longitude));
                    pointsOfInterestModel.Location = QuadrantIdentifier.getLocationInCalgary(latLongLocation);

                    db.PointsOfInterest.Add(pointsOfInterestModel);
                }
            }
            db.SaveChanges();
            return(Task.FromResult(0));
        }
        public static Task UpdateTransitLRTStations(List <TransitLRTStationsDTO> transitLRTStations)
        {
            DataModel db = new DataModel();
            List <PointsOfInterest> pointsOfInterests = db.PointsOfInterest.ToList();

            foreach (var transitLRTStation in transitLRTStations)
            {
                PointsOfInterest existingPointsOfInterest =
                    pointsOfInterests.FirstOrDefault(x => x.Name == transitLRTStation.Stationnam);

                if (existingPointsOfInterest == null)
                {
                    PointsOfInterest pointsOfInterestModel = new PointsOfInterest();
                    pointsOfInterestModel.Name      = transitLRTStation.Stationnam;
                    pointsOfInterestModel.Latitude  = transitLRTStation.Latitude;
                    pointsOfInterestModel.Longitude = transitLRTStation.Longitude;
                    pointsOfInterestModel.Type      = "CTrain";

                    var latLongLocation = new Loc(Convert.ToDouble(transitLRTStation.Latitude), Convert.ToDouble(transitLRTStation.Longitude));
                    pointsOfInterestModel.Location = QuadrantIdentifier.getLocationInCalgary(latLongLocation);

                    db.PointsOfInterest.Add(pointsOfInterestModel);
                }
            }
            db.SaveChanges();
            return(Task.FromResult(0));
        }
        //For the Police Station Locations
        public static Task UpdatePoliceLocations(List <PoliceServiceOfficesDTO> policeStations)
        {
            DataModel db = new DataModel();
            List <PointsOfInterest> pointsOfInterests = db.PointsOfInterest.ToList();

            foreach (var policeStation in policeStations)
            {
                PointsOfInterest existingPointsOfInterest =
                    pointsOfInterests.FirstOrDefault(x => x.Name == policeStation.Name);

                if (existingPointsOfInterest == null)
                {
                    PointsOfInterest pointsOfInterestModel = new PointsOfInterest();
                    pointsOfInterestModel.Name = policeStation.Name;

                    //Police Station api has longitude and latitude wrong so I had to switch them around
                    pointsOfInterestModel.Latitude  = policeStation.Longitude;
                    pointsOfInterestModel.Longitude = policeStation.Latitude.ToString();
                    pointsOfInterestModel.Type      = "Police Station";

                    var latLongLocation = new Loc(Convert.ToDouble(pointsOfInterestModel.Latitude), Convert.ToDouble(pointsOfInterestModel.Longitude));
                    pointsOfInterestModel.Location = QuadrantIdentifier.getLocationInCalgary(latLongLocation);

                    db.PointsOfInterest.Add(pointsOfInterestModel);
                }
            }
            db.SaveChanges();
            return(Task.FromResult(0));
        }
        //For the Recreational Facilities
        public static Task UpdateRecreationalLocations(List <RecreationFacilitiesDTO> recreationFacilities)
        {
            DataModel db = new DataModel();
            List <PointsOfInterest> pointsOfInterests = db.PointsOfInterest.ToList();

            foreach (var recreationFacility in recreationFacilities)
            {
                PointsOfInterest existingPointsOfInterest =
                    pointsOfInterests.FirstOrDefault(x => x.Name == recreationFacility.ComplexName);

                if (existingPointsOfInterest == null)
                {
                    PointsOfInterest pointsOfInterestModel = new PointsOfInterest();
                    pointsOfInterestModel.Name      = recreationFacility.ComplexName;
                    pointsOfInterestModel.Latitude  = recreationFacility.Latitude.ToString();
                    pointsOfInterestModel.Longitude = recreationFacility.Longitude.ToString();
                    pointsOfInterestModel.Type      = recreationFacility.FacilityType;

                    var latLongLocation = new Loc(Convert.ToDouble(pointsOfInterestModel.Latitude), Convert.ToDouble(pointsOfInterestModel.Longitude));
                    pointsOfInterestModel.Location = QuadrantIdentifier.getLocationInCalgary(latLongLocation);

                    db.PointsOfInterest.Add(pointsOfInterestModel);
                }
            }
            db.SaveChanges();
            return(Task.FromResult(0));
        }
Exemplo n.º 5
0
        private static void addQuadrantToEvent(Event eventModel)
        {
            double lat, lng;

            if (Double.TryParse(eventModel.Latitude, out lat) && Double.TryParse(eventModel.Longitude, out lng))
            {
                eventModel.Quadrant = QuadrantIdentifier.getLocationInCalgary(new Loc(lat, lng));
            }
        }