public async Task <IActionResult> Login([FromBody] LoginUserDto request)
        {
            if (request == null)
            {
                return(BadRequest("invalid credential request"));
            }

            var user = await this.GetQueryAsync <UserDto>(
                new UserGetByCredentialsQuery(request.Email, Md5HashHelper.ComputeHash(request.Password)));

            if (user == null)
            {
                return(Unauthorized());
            }

            var claims = new List <Claim>
            {
                new Claim(ClaimTypes.Name, user.Name)
            };

            foreach (var role in user.Roles)
            {
                claims.Add(new Claim(ClaimTypes.Role, role.Name));
            }

            var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345"));
            var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

            var tokeOptions = new JwtSecurityToken(
                issuer: "https://localhost:44336",
                audience: "http://localhost:4200",
                claims: claims,
                expires: DateTime.Now.AddMinutes(5),
                signingCredentials: signinCredentials
                );

            var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);

            return(Ok(new SignInDto
            {
                UserId = user.Id,
                UserName = user.Name,
                AccessToken = tokenString
            }));
        }
        protected virtual void Seed(ModelBuilder modelBuilder)
        {
            string   currentUserName = "******";
            DateTime date            = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            Guid userId = new Guid("fa64114f-9aaf-492a-a9aa-43022bfac171");
            var  user   = User.Create(userId, "Administrator");

            ((IAuditableEntity)user).CreateAuditable(date, currentUserName);

            modelBuilder.Entity <User>().HasData(user);

            Guid credentialTypeId = new Guid("105ef49d-42b6-4fb8-8d9e-52aaa16f42a9");
            var  credentialType   = CredentialType.Create(credentialTypeId, "Email address", "email");

            ((IAuditableEntity)credentialType).CreateAuditable(date, currentUserName);
            modelBuilder.Entity <CredentialType>().HasData(credentialType);

            Guid credentialId = new Guid("132a06e7-4c9e-49f9-8f94-0604f01a5c16");
            var  credential   = Credential.Create(credentialId, userId, credentialTypeId, "*****@*****.**", Md5HashHelper.ComputeHash("admin"));

            ((IAuditableEntity)credential).CreateAuditable(date, currentUserName);
            modelBuilder.Entity <Credential>().HasData(credential);
        }