public double DistanceTo(AlgCity city) { //int xDistance = Math.Abs(this.x - city.x); //int yDistance = Math.Abs(this.y - city.y); //return Math.Sqrt(xDistance * xDistance + yDistance * yDistance); if (!TourManager.IsRoutesListSet()) { using (LogisticsProject.Models.ApplicationDbContext db = new LogisticsProject.Models.ApplicationDbContext()) { List <LogisticsProject.Models.Route> routes = (from r in db.Routes.Include("cityFrom").Include("cityTo") select r).ToList(); TourManager.SetRoutesList(routes); LogisticsProject.Models.Route route = (from r in db.Routes where (r.cityFrom.CityId == this.CityId && r.cityTo.CityId == city.CityId) select r).First(); return(route.distance); } } else { List <LogisticsProject.Models.Route> routes = TourManager.GetRoutesList(); LogisticsProject.Models.Route route = (from r in routes where (r.cityFrom.CityId == this.CityId && r.cityTo.CityId == city.CityId) select r).First(); return(route.distance); } }
public double DistanceTo(City city) { //int xDistance = Math.Abs(this.x - city.x); //int yDistance = Math.Abs(this.y - city.y); //return Math.Sqrt(xDistance * xDistance + yDistance * yDistance); using (LogisticsProject.Models.ApplicationDbContext db = new LogisticsProject.Models.ApplicationDbContext()) { LogisticsProject.Models.Route route = (from r in db.Routes where (r.cityFrom.CityId == this.CityId && r.cityTo.CityId == city.CityId) select r).First(); return(route.distance); } }