/// <summary>
        /// Sending the patch request to the server for editing an exercise
        /// </summary>
        /// <param name="exercise">Name of the exercise</param>
        /// <param name="exerciseId">ID of the exercise being patched</param>
        private void SendPatchExerciseRequest(string exercise, string exerciseId)
        {
            APIRequests request = new APIRequests();

            string url = $"{request.singleExercisesEndpoint}{exerciseId}";

            string response = request.SendPatchRequestDataInBody(url, exercise);

            // TODO: Change this to show either a generic success or error message
            MessageBox.Show(response);
        }
Example #2
0
        /// <summary>
        /// Marks a given client as inactive in the system
        /// </summary>
        private void MarkClientAsInactive()
        {
            int clientId = GetClientIdFromDropdown();

            if (clientId == 0)
            {
                MessageBox.Show("Please pick a client");
            }
            else
            {
                Client client = new Client();
                client.active = "false";

                string clientAsJson = JsonConvert.SerializeObject(client);

                APIRequests request = new APIRequests();

                string url = $"{request.singleClientDetailEndpoint}{clientId}";

                string response = request.SendPatchRequestDataInBody(url, clientAsJson);

                MessageBox.Show(response);
            }
        }
Example #3
0
        private void buttonSaveEdits_Click(object sender, EventArgs e)
        {
            string clientId  = labelClientIdText.Text;
            string firstName = textBoxFirstName.Text;
            string lastName  = textBoxLastName.Text;
            string address   = textBoxAddress.Text;
            string city      = textBoxCity.Text;
            string zipCode   = textBoxZipCode.Text;
            string email     = textBoxEmail.Text;
            string state     = textBoxState.Text;
            string active    = checkBoxActive.Checked.ToString();
            string phone     = textBoxPhone.Text;

            // TODO:  Compare old values and new values.  If changed, add to an array and convert it to json to send
            Client client = new Client(clientId, firstName, lastName, active, address, city, state, zipCode, phone, email);

            string clientAsJson = JsonConvert.SerializeObject(client);

            //logger.Info(clientAsJson);

            APIRequests request = new APIRequests();

            string url = $"{request.singleClientDetailEndpoint}{clientId}";

            string response = request.SendPatchRequestDataInBody(url, clientAsJson);

            if (response.Contains("Successfully modified the client"))
            {
                MessageBox.Show("Successfully modified the client");
                this.Close();
            }
            else
            {
                MessageBox.Show("Something went wrong");
            }
        }
        /// <summary>
        /// This is called when the user wants to save their changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string id          = textBoxSessionId.Text;
            string name        = textBoxName.Text;
            string description = textBoxDescription.Text;
            string sets        = textBoxTrainingSessionSets.Text;
            string reps        = textBoxTrainingSessionReps.Text;
            string active      = checkBoxActive.Checked.ToString();

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

            // Convert the object to JSON
            string jsonSession = JsonConvert.SerializeObject(newSession);

            logger.Debug(jsonSession);

            //TODO: Finish up modifying the training session.  Make sure the methods are created first
            APIRequests request = new APIRequests();

            string url = $"{request.singleTrainingSessionEndpoint}{id}";

            logger.Debug(url);

            // Patch the training session
            var response = request.SendPatchRequestDataInBody(url, jsonSession);

            // Check the resulting json for results
            if (response.Contains("Successfully"))
            {
                // Check for new exercises to be added to the training session

                CheckForNewSessions();

                if (exercisesToAdd.Count != 0)
                {
                    // Foreach, send patch request
                    foreach (var exercise in exercisesToAdd)
                    {
                        url = $"{request.singleTrainingSessionEndpoint}{exercise.Value}/exercise/{exercise.Key}";

                        var exerciseResponse = request.SendPostRequestData(url);

                        if (exerciseResponse.Contains("error"))
                        {
                            MessageBox.Show(exerciseResponse);
                            logger.Error(exerciseResponse);
                        }
                    }
                }


                // Check for removed exericeses
                CheckForDeletedSessions();

                if (exercisesToremove.Count != 0)
                {
                    foreach (var exercise in exercisesToremove)
                    {
                        url = $"{request.singleTrainingSessionEndpoint}{exercise.Value}/exercise/{exercise.Key}";

                        var exerciseResponse = request.SendDeleteRequestData(url);

                        if (exerciseResponse.Contains("error"))
                        {
                            MessageBox.Show(exerciseResponse);
                            logger.Error(exerciseResponse);
                        }
                    }
                }


                MessageBox.Show("Completed modifying the training session");

                this.Close();
            } // End of if statement
            else
            {
                MessageBox.Show("Couldn't modify the training session");
            }
        }