/// <summary> /// Start logic to delete booking entry /// </summary> /// <param name="title">title of training</param> public void DeleteBookingEntry(string title) { //get selected Training Training training = trainingLogic.GetSelectedTraining(title); //get current booking entries Dictionary <string, TrainingStatus> currentBookingList = db.GetTrainingBooking(Global.employee.Id); if (training != null) { //Check if training, which is supposed to be deleted, is an requirement for an already booked training. If so, don't delete it List <Training> trainings = db.GetTrainingToRequirement(title); List <string> trainingWithTitleAsReq = new List <string>(); if (trainings.Count > 0) { foreach (var tmp_training in trainings) { if (currentBookingList.ContainsKey(tmp_training.Title)) { trainingWithTitleAsReq.Add(tmp_training.Title); } } //check if such trainings were found. If so, generate an error message containing thos trainings and throw an exception if (trainingWithTitleAsReq.Count > 0) { StringBuilder errorMessage = new StringBuilder(); errorMessage.Append("This training is a requirement for following trainings and thus can not be deleted. Training/s: \n"); foreach (string tmp_title in trainingWithTitleAsReq) { errorMessage.Append(tmp_title + "\n"); } throw new TrainingPlatformException(errorMessage.ToString()); } } try { currentBookingList.Remove(title); } catch (Exception ex) { Debug.Fail($"DeleteBookingEntry: {ex.Message}"); } //Delete booking entry of selected training db.DeleteTrainingBookingEntryOfEmployee(Global.employee.Id, training.Id); Global.employee.TrainingBooking = db.GetTrainingBooking(Global.employee.Id); } else { Debug.Fail($"Selected training with title '{title}' could not be found."); throw new TrainingPlatformException("The selected training could not be deleted. Please try again or contact an administrator."); } }