/// <summary>
        /// Parses the response received from the API endpoints
        /// </summary>
        /// <param name="response"></param>
        private static void ParseWebResponseToAddToDictionary(string response)
        {
            dynamic trainingSessions = JsonConvert.DeserializeObject(response);

            if (trainingSessions is null)
            {
            }
            else
            {
                // logger.Info(trainingSessions);
                // TODO: Handle different responses

                // Loop through each workout, such as id, name, description, etc
                foreach (var item in trainingSessions)
                {
                    // Training Session Details
                    //logger.Info(item);
                    string id          = item["session_id"].ToString();
                    string name        = item["sessionname"].ToString();
                    string description = item["sessiondescription"].ToString();
                    string reps        = item["sessionsets"].ToString();
                    string sets        = item["sessionreps"].ToString();
                    string active      = item["active"].ToString();

                    TrainingSession trainingSession = new TrainingSession(id, name, description, sets, reps, active);

                    TrainingSession.listOfAllTrainingSessions.Add(trainingSession);

                    // Add names and ID's to the dropdown list
                    TrainingSession.trainingSessionDictionaryForDropdown.Add(id, name);
                }
            }
        }
        /// <summary>
        /// Takes a list of training sesions in JSON format, and parses into individual sessions, and adds each to a list
        /// </summary>
        /// <param name="jsondata">A list of training sessions in JSON format</param>
        public static void ParseTrainingSessionData(string jsondata)
        {
            logger.Info(jsondata);

            if (jsondata.Contains("No training sessions found for client"))
            {
            }
            else
            {
                var         doc  = JsonDocument.Parse(jsondata);
                JsonElement root = doc.RootElement;

                //var thing1 = root[0];

                for (int i = 0; i < root.GetArrayLength(); i++)
                {
                    string id                 = root[i].GetProperty("id").ToString();
                    string sessionName        = root[i].GetProperty("sessionname").ToString();
                    string sessionDescription = root[i].GetProperty("sessiondescription").ToString();
                    string sessionSets        = root[i].GetProperty("sessionsets").ToString();
                    string sessionReps        = root[i].GetProperty("sessionreps").ToString();
                    string active             = root[i].GetProperty("active").ToString();

                    TrainingSession trainingSession = new TrainingSession(id, sessionName, sessionDescription, sessionSets, sessionReps, active);

                    listOfTrainingSessions.Add(trainingSession);
                }
            }
        }
Exemple #3
0
        public static void GetClientTrainingSessions(int clientId)
        {
            APIRequests request = new APIRequests();

            // Use the singleClientDetailEndpoint endpoint, and append {id}/trainingsessions to the URL
            string url = $"{request.singleClientDetailEndpoint}{clientId}/trainingsessions";

            var response = request.GetRequests(url);

            TrainingSession.ParseTrainingSessionData(response);
        }