Ejemplo n.º 1
0
        public async Task <IActionResult> GetGraphData(string token)
        {
            bool authenticated = await Utils.CheckFirebaseToken(_httpContextAccessor);

            //This will be triggered if the user is not logged in so this graph
            //will not be retreived from the backend database.
            if (!authenticated)
            {
                return(Json(new { nonAuthUser = true }));
            }

            //Get the current Firebase token and we know that they are logged in so there has to be a token for us to read
            var userToken = await Utils.GetUserFirebaseToken(_httpContextAccessor);

            //Get the graph owner of the current request. If its bad let the frontend know where to redirect to!
            var graphOwner = await _affinityDbContext.Users.Where(user => user.UID == userToken.Uid && user.GraphID == token).FirstOrDefaultAsync();

            //graph wasn't owned by current user redirect them to their graphs
            if (graphOwner == null)
            {
                return(Json(new { redirect = true, redirect_url = "/graphs" }));
            }

            //d9147ab4
            //879443a4
            var vertices = await _affinityDbContext.Vertices.AsNoTracking().Where(id => id.GraphID == token).ToListAsync();

            var edges = await _affinityDbContext.Edges.AsNoTracking().Where(id => id.GraphID == token).ToListAsync();

            GraphDataJson graphData = new GraphDataJson
            {
                Vertices = vertices,
                Edges    = edges
            };

            return(Content(JsonConvert.SerializeObject(graphData)));
        }
Ejemplo n.º 2
0
        public IActionResult GraphData([FromBody] ModelDummy data)
        {
            TrainingProgram program = _context.Workouts.FirstOrDefault(W => W.id == data.workoutID && W.uid == _userManager.GetUserId(User));

            var exer = _context.PExercises.FromSql("SELECT * FROM PExercises").ToList(); // Need to do this to access the data ???

            var sets = _context.ESets.FromSql("SELECT * FROM ESets").ToList();           // Need to do this to access the data ???

            List <Exercise> exercisesFromAPI = getExercisesFromAPI();
            int             exerciseID       = data.ExerciseID;

            program.Exercices.Sort((x, y) => x.day.CompareTo(y.day));
            int           max      = 0;
            int           graphMax = 0;
            int           choice   = 1;
            GraphDataJson result   = new GraphDataJson();

            foreach (ProgramExercises ex in program.Exercices)
            {
                if (ex.ExerciseID == exerciseID)
                {
                    switch (choice)
                    {
                    case 0:
                        foreach (ExerciseSets set in ex.SetInfo)
                        {
                            if (set.amount > max)
                            {
                                max = set.amount;
                            }
                            if (max > graphMax)
                            {
                                graphMax = max;
                            }
                        }
                        result.Label.Add("Day " + ex.day);
                        result.Values.Add(max.ToString());
                        max = 0;
                        break;

                    case 1:
                        foreach (ExerciseSets set in ex.SetInfo)
                        {
                            if (set.weight > max)
                            {
                                max = set.weight;
                            }
                            if (max > graphMax)
                            {
                                graphMax = max;
                            }
                        }
                        result.Label.Add("Day " + ex.day);
                        result.Values.Add(max.ToString());
                        max = 0;
                        break;
                    }
                }
            }

            //foreach (var ex in workouts[0].Exercices)
            //{
            //    foreach (var real_ex in exercisesFromAPI)
            //    {
            //        if (ex.ExerciseID == real_ex.id && (exerciseNames.GetValueOrDefault(ex.ExerciseID) == null))
            //        {
            //            exerciseNames.Add(ex.ExerciseID, real_ex.name);
            //            pro.ActualExercisesCount++;
            //        }
            //    }
            //}
            result.GraphMax     = graphMax * 2;
            result.WorkoutName  = program.name;
            result.ExerciseName = getExerciseName(exerciseID);
            return(Json(JsonConvert.SerializeObject(result)));
        }