public void AddTransitCountry(int locationId)
        {
            //CHANGE THIS TO SAVE USING THE WHOLE TRIP SO THAT IT'S THE SAME AS CREATING NORMAL POINTS
            //This whole function might actually be useless
            //locationId is the id of the location BEHIND WHICH this new point will be added

            ILocationManager m           = ObjectContainer.GetLocationManager();
            ITripManager     t           = ObjectContainer.GetTripManager();
            IMapsManager     mapsManager = ObjectContainer.GetMapsManager();

            Location orig    = m.Get(locationId);
            int      origPos = orig.Position;
            Trip     trip    = t.Get(orig.TripId);

            //First add the transit, then the crossing, because it pushes it forward and we're adding inbound travel.
            //Edit these points so that they are useful
            trip.Locations.Insert(origPos, new Location {
                Transit = true, City = new City {
                    Name = "Transit_Country"
                }
            });
            trip.Locations.Insert(origPos, new Location {
                IsCrossing = true, CrossedBorder = true
            });

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            mapsManager.SetSectionAsModified(GetUser(), trip, trip.Locations[origPos]); //This will certianly be the new location as it replaced the original

            t.Save(GetUser().ID, trip);
        }
        public Trip SetBorderCrossDate(int locationId, [FromBody] long millis)
        {
            ILocationManager m           = ObjectContainer.GetLocationManager();
            ITripManager     t           = ObjectContainer.GetTripManager();
            IMapsManager     mapsManager = ObjectContainer.GetMapsManager();

            Location l    = m.Get(locationId);
            Trip     trip = t.Get(l.TripId);

            l.CrossedAtDate   = millis;
            l.SectionModified = true;

            if (trip.Locations[l.Position - 1].Transit)
            {
                trip.Locations[l.Position - 1].DepartureDate = millis;
            }
            if (trip.Locations[l.Position + 1].Transit)
            {
                trip.Locations[l.Position + 1].ArrivalDate = millis;
            }

            mapsManager.SetSectionAsModified(GetUser(), trip, l);

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);
            m.Save(l);

            return(t.Get(l.TripId));
        }
        public async Task <Trip> SaveCity(int locationId, [FromBody] string[] names) /*First name is city, second name is country, third is place_id*/
        {
            ILocationManager m = ObjectContainer.GetLocationManager();
            Location         l = m.Get(locationId);

            ICityDbProvider c = ObjectContainer.GetCityDbProvider();

            if (names[0] == "" && names[1] == "" && names[2] == null)
            {
                l.City = null;
            }
            else
            {
                l.City = new City
                {
                    Name          = names[0],
                    CountryID     = c.GetCountryByName(names[1]).ID,
                    GooglePlaceId = names[2]
                };
            }

            m.Save(l);

            IMapsManager map  = ObjectContainer.GetMapsManager();
            ITripManager t    = ObjectContainer.GetTripManager();
            Trip         trip = t.Get(l.TripId);

            using (Trip tripX = ObjectContainer.Clone(trip)) { trip = await map.FillBorderPoints(GetUser(), tripX, l); }

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            return(trip);
        }
        public async Task <Trip> SaveDepartureTime(int locationId, [FromBody] long departureTime)
        {
            ILocationManager m = ObjectContainer.GetLocationManager();
            Location         l = m.Get(locationId);

            if (departureTime == -1)
            {
                l.DepartureTime = null;
            }
            else
            {
                l.DepartureTime = departureTime;
            }

            m.Save(l);

            IMapsManager map  = ObjectContainer.GetMapsManager();
            ITripManager t    = ObjectContainer.GetTripManager();
            Trip         trip = t.Get(l.TripId);

            using (Trip tripX = ObjectContainer.Clone(trip)) { trip = await map.FillBorderPoints(GetUser(), tripX, l); }

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            return(trip);
        }
        public async Task <Trip> SaveArrivalDate(int locationId, [FromBody] long arrivalDate)
        {
            ILocationManager m = ObjectContainer.GetLocationManager();
            Location         l = m.Get(locationId);

            l.ArrivalDate = arrivalDate;

            if (l.ArrivalDate.HasValue && l.DepartureDate.HasValue)
            {
                if (l.Food == null)
                {
                    l.Food = CreateLocationFood((int)(l.DepartureDate / 24 / 60 / 60000 - l.ArrivalDate / 24 / 60 / 60000));
                }
                else
                {
                    l.Food = CreateLocationFood((int)(l.DepartureDate / 24 / 60 / 60000 - l.ArrivalDate / 24 / 60 / 60000), l.Food);
                }
            }

            m.Save(l);

            IMapsManager map  = ObjectContainer.GetMapsManager();
            ITripManager t    = ObjectContainer.GetTripManager();
            Trip         trip = t.Get(l.TripId);

            using (Trip tripX = ObjectContainer.Clone(trip)) { trip = await map.FillBorderPoints(GetUser(), tripX, l); }

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            return(trip);
        }
        public Trip SaveCountry(int locationId, [FromBody] Country country)
        {
            ILocationManager m           = ObjectContainer.GetLocationManager();
            IMapsManager     mapsManager = ObjectContainer.GetMapsManager();
            ITripManager     tripManager = ObjectContainer.GetTripManager();
            Location         l           = m.Get(locationId);

            l.City.Country    = country;
            l.SectionModified = true;
            var trip = tripManager.Get(l.TripId);

            mapsManager.SetSectionAsModified(GetUser(), trip, l);

            m.Save(l);

            return(trip);
        }
        public Trip Delete([FromBody] int[] locationIds)
        {
            ILocationManager m           = ObjectContainer.GetLocationManager();
            ITripManager     tripManager = ObjectContainer.GetTripManager();
            IMapsManager     mapsManager = ObjectContainer.GetMapsManager();

            Location l    = m.Get(locationIds[0]);
            Location lAlt = m.Get(locationIds[1]);

            Trip trip = tripManager.Get(l.TripId);

            //There will always be a crossing there and we want to see if the other one is a transit. If it is, the section, into which it belongs, is modified
            if (l.IsCrossing)
            {
                if (lAlt.Transit)
                {
                    mapsManager.SetSectionAsModified(GetUser(), trip, lAlt);
                }
            }
            else
            {
                if (l.Transit)
                {
                    mapsManager.SetSectionAsModified(GetUser(), trip, l);
                }
            }

            //Order in which they are deleted is important here, deleting from last to first in the array of locationIds
            for (var j = locationIds.Length - 1; j >= 0; j--)
            {
                for (var i = 0; i < trip.Locations.Count; i++)
                {
                    if (trip.Locations[i].ID == locationIds[j])
                    {
                        trip.Locations[i].Deleted = true;
                        break;
                    }
                }
            }

            tripManager.Save(GetUser().ID, trip);

            return(trip);
        }
        public async Task <Trip> SaveInboundTravel(int locationId, [FromBody] TravelType travelType)
        {
            ILocationManager m = ObjectContainer.GetLocationManager();
            Location         l = m.Get(locationId);

            l.InboundTravelType = travelType;

            m.Save(l);

            IMapsManager map  = ObjectContainer.GetMapsManager();
            ITripManager t    = ObjectContainer.GetTripManager();
            Trip         trip = t.Get(l.TripId);

            using (Trip tripX = ObjectContainer.Clone(trip)) { trip = await map.FillBorderPoints(GetUser(), tripX, l); }

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            return(trip);
        }
Example #9
0
        public Trip SaveAndReturnTrip([FromBody] Trip trip)
        {
            ITripManager m           = ObjectContainer.GetTripManager();
            IMapsManager mapsManager = ObjectContainer.GetMapsManager();

            for (var i = 0; i < trip.Locations.Count; i++)
            {
                trip.Locations[i].Position = i;
            }

            if (trip.ID > 0)
            {
                Trip old = m.Get(trip.ID);
                List <List <Location> > oldSections = mapsManager.SplitTripIntoSections(old);

                if (oldSections == null)
                {
                    return(m.SaveAndReturn(GetUser().ID, trip));
                }

                List <List <Location> > sections = mapsManager.SplitTripIntoSections(trip);

                //If a new point is added, it shows up as a new section here. If a transit point is added, it gets added to a section and changes the length
                Location modified = null;
                for (var i = 0; i < oldSections.Count; i++)
                {
                    if (oldSections[i].Count != sections[i].Count)
                    {
                        modified = sections[i][1];
                    }
                }

                if (modified != null)
                {
                    mapsManager.SetSectionAsModified(GetUser(), trip, modified);
                }
            }

            return(m.SaveAndReturn(GetUser().ID, trip));
        }
Example #10
0
        public async Task <Trip> ResetSectiondModifications(int locationId)
        {
            ILocationManager m           = ObjectContainer.GetLocationManager();
            ITripManager     t           = ObjectContainer.GetTripManager();
            IMapsManager     mapsManager = ObjectContainer.GetMapsManager();

            Location l    = m.Get(locationId);
            Trip     trip = t.Get(l.TripId);

            l.SectionModified = false;

            mapsManager.SetSectionAsNotModified(GetUser(), trip, l);

            m.Save(l);

            using (Trip tripX = ObjectContainer.Clone(trip)) { trip = await mapsManager.FillBorderPoints(GetUser(), tripX, l); }

            trip.ArrangePoints();

            t.Save(GetUser().ID, trip);

            return(trip);
        }