Example #1
0
        public IEnumerable <EmployeeModel> GetAllEmployeeDetail()
        {
            List <EmployeeModel> result = new List <EmployeeModel>();
            var employees = base.GetAll();

            foreach (var employee in employees)
            {
                employee.Personal = _personalService.Find(employee.PersonalId, "ApplicationUser");
                result.Add(EmployeeModel.GetModel(employee));
            }
            return(result);
        }
Example #2
0
        public IEnumerable <FamerModel> GetAllFamerDetail()
        {
            List <FamerModel> result = new List <FamerModel>();
            var famers = base.GetAll();

            foreach (var famer in famers)
            {
                famer.Personal = _personalService.Find(famer.PersonalId, "ApplicationUser");
                result.Add(FamerModel.GetModel(famer));
            }
            return(result);
        }
        private async Task <object> GenerateJwtToken(string username, ApplicationUser user)
        {
            var claims = new List <Claim>
            {
                new Claim(JwtRegisteredClaimNames.Sub, username),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
            };
            //Add roles to token
            var roles = await _userManager.GetRolesAsync(user);

            foreach (string role in roles)
            {
                claims.Add(new Claim(ClaimTypes.Role, role));
            }
            //Add full name to token
            var personal = _personalService.Find(user.PersonalId);

            claims.Add(new Claim(ClaimTypes.Name, personal.FullName));

            var key     = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"]));
            var creds   = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var expires = DateTime.Now.AddDays(Convert.ToDouble(_configuration["JwtExpireDays"]));

            var token = new JwtSecurityToken(
                _configuration["JwtIssuer"],
                _configuration["JwtIssuer"],
                claims,
                expires: expires,
                signingCredentials: creds
                );

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }