Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetCastles()
        {
            var locations = _directionService.GetDirection(_myLocation, _locations);

            locations.Insert(0, _myLocation);
            var routes  = new List <RouteModel>();
            var castles = new List <CastleModel>();

            castles.Add(new CastleModel()
            {
                Position = locations[0],
                Index    = 0
            });
            for (int i = 1; i < locations.Count; i++)
            {
                var castle = new CastleModel()
                {
                    Position = locations[i],
                    Index    = i
                };
                castles.Add(castle);
                routes.Add(new RouteModel(castles[i - 1], castles[i]));
                castles[i - 1].RouteCount++;
                castles[i].RouteCount++;
            }
            routes.Add(new RouteModel(castles[0], castles[castles.Count - 1]));
            castles[0].RouteCount++;
            castles[castles.Count - 1].RouteCount++;
            var min = 0;
            var max = 18;

            while (max - min > 1)
            {
                routes.Add(new RouteModel(castles[min], castles[max]));
                castles[min].RouteCount++;
                castles[max].RouteCount++;
                min++;
                max--;
            }
            return(Ok(new GetCastlesResponse
            {
                Castles = castles,
                Routes = routes
            }));
        }
Ejemplo n.º 2
0
 public RouteModel(CastleModel fromCastle, CastleModel toCastle)
 {
     FromCastle = fromCastle;
     ToCastle   = toCastle;
 }