public async Task <Trip> SaveArrivalTime(int locationId, [FromBody] long arrivalTime) { ILocationManager m = ObjectContainer.GetLocationManager(); Location l = m.Get(locationId); if (arrivalTime == -1) { l.ArrivalTime = null; } else { l.ArrivalTime = arrivalTime; } 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 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); }