/// <summary> /// Deletes the persisted user /// </summary> /// <param name="user"></param> public void DeleteUser(User user) { if (user != null) { _dbUser.DeleteUser(user); } }
public void Delete() { bool exit; ICollection <Trainer> trainers = DBTrainer.ReadTrainers(); if (trainers.Count() == 0) { ConsoleUI.ShowLine("no trainers yet"); ConsoleUI.ReadKey(); ConsoleUI.Clear(); return; } else { ConsoleUI.ShowLine("select trainer to delete, type 0 to exit"); foreach (Trainer t in trainers) { ConsoleUI.ShowLine(t); } } exit = ConsoleUI.GetInt(out int TrainerID, "give trainer id: "); if (exit) { return; } Trainer trainer; try { trainer = trainers.Where(t => t.Id == TrainerID).First(); } catch (Exception) { ConsoleUI.ShowLine($"NO TRAINER FOUND WITH ID: {TrainerID}"); ConsoleUI.ReadKey(); return; } bool confirmed = ConsoleUI.GetConfirmation($"are you sure you want to delete trainer {trainer.FirstName} {trainer.LastName}? [y/n]: "); int result = 0; if (confirmed) { try { result = DBTrainer.DeleteTrainer(TrainerID); if (result == 0) { throw new Exception("could NOT delete trainer"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } try { result = DBUser.DeleteUser(TrainerID); if (result == 0) { throw new Exception("could NOT delete user"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine("trainer deleted successfully"); ConsoleUI.ReadKey(); } }
public void Delete() { bool exit; ICollection <Student> students = DBStudent.ReadStudents(); if (students.Count() == 0) { ConsoleUI.ShowLine("No students yet"); ConsoleUI.ReadKey(); ConsoleUI.Clear(); return; } else { ConsoleUI.ShowLine("select student to delete, type 0 to exit"); foreach (Student s in students) { ConsoleUI.ShowLine(s); } } exit = ConsoleUI.GetInt(out int StudentID, "give student id: "); if (exit) { return; } Student student; try { student = students.Where(s => s.Id == StudentID).First(); } catch (Exception) { ConsoleUI.ShowLine($"NO STUDENT FOUND WITH ID: {StudentID}"); ConsoleUI.ReadKey(); return; } bool confirmed = ConsoleUI.GetConfirmation($"are you sure you want to delete student {student.FirstName} {student.LastName}? [y/n]: "); int result = 0; if (confirmed) { try { result = DBStudent.DeleteStudent(StudentID); if (result == 0) { throw new Exception("could NOT delete student"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } try { result = DBUser.DeleteUser(StudentID); if (result == 0) { throw new Exception("could NOT delete user"); } } catch (Exception e) { ConsoleUI.ShowLine(e.Message); ConsoleUI.ReadKey(); return; } ConsoleUI.ShowLine("student deleted successfully"); ConsoleUI.ReadKey(); } }