/// <summary> /// Get Training with given title /// </summary> /// <param name="title">Title of training</param> /// <returns></returns> public Training GetSelectedTraining(string title) { List <Training> trainings = db.GetTrainings(); foreach (var training in trainings) { if (training.Title.Equals(title)) { return(training); } } return(null); }
public void DeleteTraining(int trainingId) { //Check if training is booked by employees and in status in process List <TrainingBookingEntry> entries = db.GetBookingsWithStatus(trainingId, (int)TrainingStatus.InProcess); //if not, proceed, else throw an exception if (entries.Count == 0) { db.DeleteTraining(trainingId); Training.Trainings = db.GetTrainings(); } else { throw new TrainingPlatformException("There are employee which are currently undergo this training and therefor it can not be deleted."); } }
/// <summary> /// Login with email and password /// </summary> /// <param name="emailAddress">Email address</param> /// <param name="password">Password</param> /// <returns>true if login successfull</returns> public bool Login(string emailAddress, string password) { //Get user account UserAccountEntry userCredentials = db.GetUserAccountCredentials(emailAddress); if (userCredentials == null) { return(false); } //verify password if (PasswordCryptoLogic.VerifyPassword(password, userCredentials.PasswordSalt, userCredentials.PasswordHash)) { Employee employee = db.GetEmployeeById(userCredentials.EmployeeId); if (employee == null) { Debug.WriteLine($"ERROR during retrieving employee with id {userCredentials.EmployeeId}"); throw new Exception(); } employee.EmailAddress = emailAddress; userCredentials = null; //Get all trainings Training.Trainings = db.GetTrainings(); //Get all training bookings of current user employee.TrainingBooking = db.GetTrainingBooking(employee.Id); if (employee.Role.Equals(Role.ROLE_ADMIN)) { Employee.Employees = db.GetAllEmployees(); } //assign employee object to global employee Global.employee = employee; return(true); } return(false); }