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 string Export(int id)
        {
            ITripManager m = ObjectContainer.GetTripManager();

            Trip t = m.Get(id);

            if (t.Title == null || t.Title == "" || t.Project == null || t.Project == "" || t.Purpose == null || t.Purpose == "" || t.Task == null || t.Task == "")
            {
                return(null);
            }

            t.Exported = true;

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

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("iwjrgoirwhoinwriognmcgweiuohgowimeugmvetwiuhvgkjtejklgjwklfkwipockpoeqkgpovet")); //string is a sectret that should be replaced
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, t.ID.ToString())
                }),
                Expires            = DateTime.UtcNow.AddSeconds(30), //Increase if problems with expiring tokens
                SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature),
                Issuer             = "tieto-trippi-app",
                Audience           = "everyone"
            };
            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            return(tokenString);
        }
        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);
        }
Beispiel #5
0
 public virtual void Setup()
 {
     GenerateTrips();
     _uow            = Substitute.For <IUnitOfWork>();
     _tripRepository = Substitute.For <ITripRepository>();
     Repository.Entities.Returns(Trips.Values.AsQueryable());
     Repository.When(repo => repo.Add(Arg.Any <Trip>()))
     .Do(
         _ =>
     {
         var trip = (Trip)_[0];
         Trips.Add(trip.Id, trip);
     });
     Repository.When(repo => repo.Update(Arg.Any <Trip>()))
     .Do(
         _ =>
     {
         var trip       = (Trip)_[0];
         Trips[trip.Id] = trip;
     });
     Repository.When(repo => repo.Delete(Arg.Any <Trip>()))
     .Do(
         _ =>
     {
         var trip = (Trip)_[0];
         Trips.Remove(trip.Id);
     });
     Repository.GetById(Arg.Any <string>()).Returns(_ => Trips[(string)_[0]]);
     _tripManager = new TripManager(Uow, Repository);
 }
        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 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 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);
        }
Beispiel #9
0
        public void SaveComment(int id, [FromBody] string comment)
        {
            ITripManager m = ObjectContainer.GetTripManager();
            Trip         t = m.Get(id);

            t.Comment = comment;

            m.Save(GetUser().ID, t);
        }
Beispiel #10
0
        public void SaveTask(int id, [FromBody] string task)
        {
            ITripManager m = ObjectContainer.GetTripManager();
            Trip         t = m.Get(id);

            t.Task = task;

            m.Save(GetUser().ID, t);
        }
Beispiel #11
0
        public void SaveProject(int id, [FromBody] string project)
        {
            ITripManager m = ObjectContainer.GetTripManager();
            Trip         t = m.Get(id);

            t.Project = project;

            m.Save(GetUser().ID, t);
        }
Beispiel #12
0
        public void SavePurpose(int id, [FromBody] string purpose)
        {
            ITripManager m = ObjectContainer.GetTripManager();
            Trip         t = m.Get(id);

            t.Purpose = purpose;

            m.Save(GetUser().ID, t);
        }
Beispiel #13
0
        public void SaveTitle(int id, [FromBody] string title)
        {
            ITripManager m = ObjectContainer.GetTripManager();
            Trip         t = m.Get(id);

            t.Title = title;

            m.Save(GetUser().ID, t);
        }
Beispiel #14
0
        public Trip TripDetails(int id)
        {
            ITripManager m = ObjectContainer.GetTripManager();

            Trip trip = m.Get(id);

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

            return(trip);
        }
Beispiel #15
0
        public int SaveTrip([FromBody] Trip trip)
        {
            ITripManager m = ObjectContainer.GetTripManager();

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

            return(m.Save(GetUser().ID, trip));
        }
Beispiel #16
0
        public IList <Trip> GetTripList()
        {
            ITripManager m = ObjectContainer.GetTripManager();

            IList <Trip> trips = m.GetList(GetUser().ID);

            for (var i = 0; i < trips.Count; i++)
            {
                trips[i].ArrangePoints();
            }

            return(trips);
        }
        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);
        }
Beispiel #18
0
        public IActionResult GetPdf(string token)
        {
            ITripManager m = ObjectContainer.GetTripManager();

            ClaimsIdentity identity = GetIdentityFromToken(token);

            if (identity == null)
            {
                return(Unauthorized());
            }

            Trip t = m.Get(Convert.ToInt32(identity.Name));

            IPDFManager pm = ObjectContainer.GetPDFManager();

            //Don't let the user export it if Title or anything else is not defined!
            return(File(pm.CreatePdf(t), "application/pdf" /*, t.Title + ".pdf"*/)); //Uncomment this so that the file gets downloaded and not opened
        }
        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);
        }
Beispiel #20
0
        public Trip DuplicateTrip([FromBody] int id)
        {
            ITripManager m = ObjectContainer.GetTripManager();

            Trip orig = m.Get(id);

            Trip newTrip = ObjectContainer.Clone(orig);

            newTrip.Title    = orig.Title != null && orig.Title != "" ? orig.Title + " - Copy" : "Copy of Unnamed trip";
            newTrip.ID       = 0;
            newTrip.Exported = false;
            for (var i = 0; i < newTrip.Locations.Count(); i++)
            {
                var l = newTrip.Locations.ElementAt(i);
                newTrip.Locations.RemoveAt(i);
                newTrip.Locations.Insert(i, l);
                l.ID = 0;
                if (l.City != null)
                {
                    l.City.ID = 0;
                }
                if (l.Food != null)
                {
                    l.Food.ID = 0;
                }
            }
            if (newTrip.Exchange != null)
            {
                newTrip.Exchange.ID = 0;
                for (var i = 0; i < newTrip.Exchange.Rates.Count(); i++)
                {
                    newTrip.Exchange.Rates[i].ID = 0;
                }
            }

            m.Save(GetUser().ID, newTrip);

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

            return(newTrip);
        }
        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);
        }
Beispiel #22
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));
        }
        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);
        }
 public UserAccountController(IUsersManager userManager, ITripManager tripManager)
 {
     this._userManager = userManager;
     this._tripManager = tripManager;
 }
Beispiel #25
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);
        }
 public SuggestTripController(ITripManager tripManager)
 {
     this._tripManager = tripManager;
 }
Beispiel #27
0
        public void DeleteTrip([FromBody] int id)
        {
            ITripManager m = ObjectContainer.GetTripManager();

            m.Delete(id);
        }
Beispiel #28
0
        private List<Trip> _trips; // static ???

        #endregion Fields

        #region Constructors

        public FindTripController(ITripManager tripManager)
        {
            this._tripManager = tripManager;
        }
Beispiel #29
0
 /// <summary>
 /// Constructor for TripController. Takes in two interface parameters and defines them to the two corresponding properties.
 /// </summary>
 /// <param name="trips">Takes in a ITripManager variable.</param>
 /// <param name="users">Takes in a IUserManager variable.</param>
 public TripController(ITripManager trips, IUserManager users)
 {
     _trips = trips;
     _users = users;
 }
Beispiel #30
0
 public TripsController(ITripManager tripManager)
 {
     _tripManager = tripManager;
 }
Beispiel #31
0
 public Trip(IHostingEnvironment hostingEnvironment, ITripManager tripManager, IMapper mapper, IAccountInfo accountInfo) : base(hostingEnvironment)
 {
     _tripManager = tripManager;
     _mapper      = mapper;
     _accountInfo = accountInfo;
 }