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); }
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); }
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 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> 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> 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 void SaveTitle(int id, [FromBody] string title) { ITripManager m = ObjectContainer.GetTripManager(); Trip t = m.Get(id); t.Title = title; m.Save(GetUser().ID, t); }
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); }
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); }
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); }
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); }
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)); }
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 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); }
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); }