コード例 #1
0
        public TripPossiblePlace Create(TripPossiblePlace toCreate)
        {
            _db.TripPossiblePlaces.Add(toCreate);
            _db.SaveChanges();

            return(toCreate);
        }
コード例 #2
0
        public static TripPossiblePlaceViewModel ToViewModel(this TripPossiblePlace possiblePlace)
        {
            var vm = new TripPossiblePlaceViewModel()
            {
                TripId    = possiblePlace.TripId,
                PlaceId   = possiblePlace.PlaceId,
                PlaceType = possiblePlace.PlaceType,
                Distance  = possiblePlace.Distance,
                Place     = possiblePlace.Place?.ToViewModel()
            };

            return(vm);
        }
コード例 #3
0
        protected void AddPossiblePlaceToTrip(Trip trip, Reading reading, TripPossiblePlaceType type)
        {
            var ownerId        = trip.Car.OwnerId;
            var possiblePlaces = _placeService.GetPlacesNearby(reading.Latitude,
                                                               reading.Longitude, 150, ownerId);

            foreach (var place in possiblePlaces)
            {
                var possiblePlace = new TripPossiblePlace()
                {
                    Trip      = trip,
                    TripId    = trip.TripId,
                    Place     = place,
                    PlaceType = type,
                    Distance  = Convert.ToDecimal(GeographyUtils.CalculateDistanceBetweenLocations(
                                                      reading.Latitude, reading.Longitude, place.Latitude, place.Longitude)),
                    Active = true
                };

                _tripPossiblePlaceService.Create(possiblePlace);
            }

            _logger.Debug($"Added possible {type.ToString()} to trip {trip.TripId}");
        }