private void MarkExericiseAsInactive() { int exerciseId = GetExericseIdFromDropdown(); if (exerciseId == 0) { MessageBox.Show("Please pick an exercise from the dropdown"); } else { APIRequests request = new APIRequests(); string url = $"{request.singleExercisesEndpoint}{exerciseId}"; string response = request.SendDeleteRequestData(url); if (response.Contains("Successfully marked the exercise inactive")) { MessageBox.Show("Successfully marked the exercise inactive"); // Now clear the table dataGridViewExercises.DataSource = ""; // Refresh the dropdown Exercise.GetExercises(); PopulateDropdownMenu(); } else { MessageBox.Show("Sorry, couldn't mark the exercise as inactive"); } } }
private void buttonDeleteWorkout_Click(object sender, EventArgs e) { DialogResult result1 = MessageBox.Show("This will remove the workout from your history, and it cannot be recovered. Do you wish to continue?", "This will delete a workout", MessageBoxButtons.YesNo); if (result1.ToString() == "No") { return; } int workoutId = 0; foreach (DataGridViewRow item in this.dataGridViewWorkoutHistory.SelectedRows) { // TODO: Be able to select the session to remove it string workoutIdFromGrid = Convert.ToString(item.Cells[0].Value); workoutId = Convert.ToInt32(workoutIdFromGrid); } if (workoutId == 0) { MessageBox.Show("Please select an entire row"); } else { APIRequests request = new APIRequests(); string url = $"{request.getSpecificWorkoutHistoryItem}{workoutId}"; logger.Info(url); string response = request.SendDeleteRequestData(url); if (response.Contains("Successfully removed workout from client")) { MessageBox.Show("Successfully removed workout from client"); GetClientInformation(); } else { logger.Error(response); MessageBox.Show("Something went wrong and workout not removed"); } } }
/// <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"); } }