Beispiel #1
0
        public void SetSectionAsModified(User user, Trip trip, Location location)
        {
            List <List <Location> > sections = SplitTripIntoSections(trip);

            for (var i = 0; i < sections.Count; i++)
            {
                var contains = false;
                for (var k = 0; k < sections[i].Count; k++)
                {
                    if (sections[i][k].ID == location.ID)
                    {
                        contains = true;
                    }
                }
                if (contains)
                {
                    for (var j = 0; j < sections[i].Count; j++)
                    {
                        if (sections[i][j].Transit || sections[i][j].IsCrossing)
                        {
                            sections[i][j].SectionModified = true;
                        }
                    }
                }
            }

            ITripManager m = ObjectContainer.GetTripManager();

            m.Save(user.ID, trip);
        }
Beispiel #2
0
        public async Task <Trip> FillBorderPoints(User user, Trip trip, Location editedLocation)
        {
            if (trip.Locations.Count < 3)
            {
                return(trip);
            }

            trip.ArrangePoints();

            ITripManager m = ObjectContainer.GetTripManager();

            trip = m.SaveAndReturn(user.ID, trip);

            //--------------------------------------------

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

            for (var j = 0; j < sections.Count; j++)
            {
                List <Location> section = sections[j];
                //section[1] is most probably always a border cross and it must always exist
                if (section[1].SectionModified)
                {
                    continue;
                }

                EraseListLocationPoints(section);

                //This for loop should be useless, as at this point there is only one border-cross point in the section
                for (var i = 0; i < section.Count; i++)
                {
                    if (i == 0 || i == section.Count - 1)
                    {
                        continue;
                    }
                    var l  = section.ElementAt(i);
                    var ln = section.ElementAt(i + 1);
                    var lp = section.ElementAt(i - 1);
                    //if (l.ID != editedLocation.ID && ln.ID != editedLocation.ID && lp.ID != editedLocation.ID) continue;
                    //This partially solves the pointless filling, but it still checks for both inbound and outbound crosses, but it's not always necesarry!!!
                    if (l.IsCrossing && lp.DepartureDate.HasValue && lp.DepartureTime.HasValue && ln.ArrivalDate.HasValue && ln.ArrivalTime.HasValue && ln.InboundTravelType.HasValue)
                    {
                        l.CrossedBorder = lp.City.CountryID != ln.City.CountryID;
                        if (l.CrossedBorder)
                        {
                            BorderCrossObject o = await GetBorderCrossTime(lp, ln, section, i);

                            if (o != null)
                            {
                                long transitPointTime = Convert.ToInt64(o.CrossedAt % (60000 * 60 * 24));
                                long transitPointDate = Convert.ToInt64(o.CrossedAt - transitPointTime);
                                l.CrossedAtDate = transitPointDate;
                                l.CrossedAtTime = transitPointTime;
                                i += o.IncrementBy;
                            }
                            else
                            {
                                l.CrossedAtDate = -1;
                                l.CrossedAtTime = -1;
                            }
                        }
                    }
                    else
                    {
                        l.CrossedAt = null;
                    }
                }
            }

            trip.Locations = StichTogetherSections(sections);

            //----------------------------------------

            trip.Locations.OrderBy(x => x.Position);

            return(trip);
        }