コード例 #1
0
        public async Task <Employee> CreateEmployee(EmployeeViewModel EmployeeViewModel, string userName)
        {
            #region Add New Employee

            Employee EmployeeModel = new Entities.Models.Employee();
            EmployeeModel.Name         = EmployeeViewModel.Name;
            EmployeeModel.Mobile       = EmployeeViewModel.Mobile;
            EmployeeModel.Email        = EmployeeViewModel.Email;
            EmployeeModel.DepartmentId = EmployeeViewModel.DepartmentId;
            EmployeeModel.Age          = EmployeeViewModel.Age;
            EmployeeModel.IsActive     = EmployeeViewModel.IsActive;
            await _context.Employee.AddAsync(EmployeeModel);

            #endregion
            return(EmployeeModel);
        }
コード例 #2
0
        public string GenerateJSONWebToken(Entities.Models.Employee userInfo)
        {
            var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
            var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(_config["Jwt:Issuer"],
                                             _config["Jwt:Issuer"],
                                             claims: new Claim[]
            {
                new Claim(ClaimTypes.Role, userInfo.Role.Id.ToString())
            },
                                             expires: DateTime.Now.AddMinutes(this.tokenExpiryDurationInMins),
                                             signingCredentials: credentials);

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
コード例 #3
0
        public async Task EmployeesController_GetEmployeeForCompany_Should_ReturnTheEmployee()
        {
            var companyId    = Guid.NewGuid();
            var employeeId   = Guid.NewGuid();
            var trackChanges = false;

            var employeeEntity = new Entities.Models.Employee
            {
                CompanyId = companyId,
                Id        = employeeId,
                Age       = 23,
                Name      = "Test Employee",
                Position  = "Manager"
            };


            _mockedEmployeeRepository.Setup(
                employeeRepo => employeeRepo.GetEmployeeAsync(companyId, employeeId, trackChanges)
                )
            .Returns(
                Task.FromResult(
                    employeeEntity
                    )
                );

            _mockedCompanyRepository.Setup(
                companyRepo => companyRepo.GetCompanyAsync(companyId, trackChanges)
                )
            .Returns(
                Task.FromResult(
                    new Entities.Models.Company
            {
                Id        = companyId,
                Address   = "test address",
                Country   = "Test Country",
                Employees = null,
                Name      = "Test company Name"
            }
                    )
                );

            EmployeesController employeesController = new EmployeesController(
                _mockedRepositoryManager.Object,
                _mockedLogger.Object,
                _mapper,
                null,
                null
                );

            var okObjectResult = await employeesController.GetEmployeeForCompany(companyId, employeeId) as OkObjectResult;

            var objectResult = okObjectResult as ObjectResult;
            var response     = objectResult.Value as EmployeeDto;

            using var scope = new AssertionScope();

            okObjectResult
            .StatusCode
            .Should()
            .Be((int)HttpStatusCode.OK);

            var expectedEmployeeDto = _mapper.Map <EmployeeDto>(employeeEntity);

            response
            .Should()
            .BeEquivalentTo(expectedEmployeeDto);
        }