Beispiel #1
0
 /// <summary>
 /// Create an employee with password hash and salt
 /// Sends mail with first login password
 /// </summary>
 /// <param name="employee"> EmployeeBO to create</param>
 /// <returns> new EmployeeBO</returns>
 public EmployeeBO Create(EmployeeBO employee)
 {
     using (var uow = _facade.UnitOfWork)
     {
         password     = employee.Password;
         _newEmployee = uow.EmployeeRepository.Create(_employeeConverter.Convert(employee));
         PasswordHash.CreatePasswordHash(password, out passwordHash, out passwordSalt);
         _newEmployee.PasswordHash  = passwordHash;
         _newEmployee.PasswordSalt  = passwordSalt;
         _newEmployee.PasswordReset = true;
         _newEmployee.IsAdmin       = "User";
         // _mailto.mailTo(_newEmployee.Username, password, _newEmployee.Firstname);
         uow.Complete();
         return(_employeeConverter.Convert(_newEmployee));
     }
 }
Beispiel #2
0
        public IActionResult Login([FromBody] LoginInput LoginInput)
        {
            var user = _facade.EmployeeService.GetAll().FirstOrDefault(u => u.Username == LoginInput.Username);

            // check if username exists
            if (user == null)
            {
                return(Unauthorized());
            }

            // check if password is correct
            if (!VerifyPasswordHash(LoginInput.Password, user.PasswordHash, user.PasswordSalt))
            {
                return(Unauthorized());
            }

            // Authentication successful
            return(Ok(new
            {
                passwordreset = user.PasswordReset,
                id = user.Id,
                username = user.Username,
                isadmin = user.IsAdmin,
                token = GenerateToken(_employeeConverter.Convert(user)),
            }));
        }
Beispiel #3
0
        public async Task <EmployeeViewModel> GetEmployeeReportsToAsync(int id,
                                                                        CancellationToken ct = default(CancellationToken))
        {
            var employee = await _employeeRepository.GetReportsToAsync(id, ct);

            return(EmployeeConverter.Convert(employee));
        }
        public void RegexTest()
        {
            string input = @"""Mattias Asplund"" 46 35000.00 070-6186120 ";


            EmployeeConverter sut = new EmployeeConverter();
            var results           = sut.Convert(input);
        }
Beispiel #5
0
        public void Convert()
        {
            string input  = @"""Mattias Asplund"" 46 35000.00 070-6186120";
            var    sut    = new EmployeeConverter();
            string actual = sut.Convert(input);

            Assert.AreEqual("Asplund, Mattias (Lön: 35000,00 SEK) Telefon:070-6186120 Födelseår:1971", actual);
        }
Beispiel #6
0
        public async Task <EmployeeViewModel> GetEmployeeByIdAsync(int id,
                                                                   CancellationToken ct = default(CancellationToken))
        {
            var employeeViewModel = EmployeeConverter.Convert(await _employeeRepository.GetByIdAsync(id, ct));

            employeeViewModel.Customers = await GetCustomerBySupportRepIdAsync(employeeViewModel.EmployeeId, ct);

            employeeViewModel.DirectReports = await GetEmployeeDirectReportsAsync(employeeViewModel.EmployeeId, ct);

            employeeViewModel.Manager = employeeViewModel.ReportsTo.HasValue
                ? await GetEmployeeReportsToAsync(employeeViewModel.ReportsTo.GetValueOrDefault(), ct)
                : null;

            employeeViewModel.ReportsToName = employeeViewModel.ReportsTo.HasValue
                ? $"{employeeViewModel.Manager.LastName}, {employeeViewModel.Manager.FirstName}"
                : string.Empty;
            return(employeeViewModel);
        }