/// <summary>
        /// Checks if training has a certain training status
        /// </summary>
        /// <param name="training">Title of training</param>
        /// <param name="status">supposed status of training</param>
        /// <returns> true if training has status and false if it hasn't</returns>
        public bool HasTrainingStatus(string training, TrainingStatus status)
        {
            Dictionary <string, TrainingStatus> bookingList = db.GetTrainingBooking(Global.employee.Id);

            TrainingStatus tmp_status;

            if (bookingList.TryGetValue(training, out tmp_status))
            {
                if (tmp_status == status)
                {
                    return(true);
                }
            }


            return(false);
        }
Esempio n. 2
0
        /// <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);
        }