Beispiel #1
0
        public async Task <List <Route> > GetRoutesAsync(string userId)
        {
            var result = new List <Route>();

            // Create Tasks
            var gymTask     = _topLoggerService.GetGym("klimax");
            var routesTask  = _topLoggerService.GetRoutes(49);
            var ascendsTask = _topLoggerService.GetAscends(userId, 49);

            // Gym data
            var gym   = await gymTask;
            var walls = gym.walls.ToDictionary(x => x.id);
            var holds = gym.holds.ToDictionary(x => x.id);

            // Routes
            var routesFilterd = (await routesTask)
                                .Where(x => walls.ContainsKey(x.wall_id))
                                .ToList();

            // Ascends
            var ascends = await ascendsTask;

            foreach (var apiRoute in routesFilterd)
            {
                var route = new Route
                {
                    Id          = apiRoute.id,
                    Grade       = GradeConvertor(apiRoute.grade),
                    GradeNumber = apiRoute.grade,
                    Rope        = apiRoute.rope_number == 0 ? "/" : apiRoute.rope_number.ToString(),
                    Wall        = walls[apiRoute.wall_id].name
                };

                // Ascend
                var routeAscends = ascends.Where(x => x.climb_id == apiRoute.id);
                foreach (var ascend in routeAscends)
                {
                    route.Ascends.Add(new Ascend
                    {
                        LoggedAt = ascend.date_logged,
                        TopType  = (RouteTopType)ascend.checks
                    });
                }

                // Color
                var hold = holds[apiRoute.hold_id];
                route.Color = new RouteColor()
                {
                    Name  = hold.brand,
                    Value = hold.color
                };
                result.Add(route);
            }
            return(result);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var api = new TopLoggerService();


            var test = api.GetAscends();
        }