Role lista hozzáadása

This commit is contained in:
2025-03-18 12:12:12 +01:00
parent 5097757cfb
commit 8c1966ef4c
13 changed files with 1124 additions and 39 deletions
+68 -8
View File
@@ -15,6 +15,7 @@ using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using WorkFlowCheck.DL.Entities;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity;
namespace WorkFlowCheck.BL.Services
{
@@ -30,6 +31,7 @@ namespace WorkFlowCheck.BL.Services
_mapper = mapper;
_configuration = configuration;
}
public async Task<UserDTO> GetUserAsync(int Id)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
@@ -48,7 +50,6 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<List<UserDTO>> GetAllUserAsync()
{
var retVal = new List<UserDTO>
@@ -72,7 +73,6 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<UserDTO> Authenticate(string userName, string password)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
@@ -113,7 +113,6 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public string GenerateJwtToken(UserDTO userDTO)
{
var jwtSettings = _configuration.GetSection("Jwt");
@@ -144,13 +143,74 @@ namespace WorkFlowCheck.BL.Services
return new JwtSecurityTokenHandler().WriteToken(token);
}
public async Task<UserDTO> UpdateUserAsync(UserDTO userDTO)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
try
{
if (userDTO.Id == 0)
{
var user = new User();
user.UserName = userDTO.UserName;
user.FirstName = userDTO.FirstName;
user.LastName = userDTO.LastName;
user.Email = userDTO.Email;
user.JwtToken = "";
public Task<UserDTO> UpdateUserAsync(UserDTO userDTO) => throw new NotImplementedException();
public Task<RoleDTO> GetRoleAsync(int Id) => throw new NotImplementedException();
public Task<List<RoleDTO>> GetAllRoleAsync() => throw new NotImplementedException();
public Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
Task<UserRoleDTO> IUserService.GetUserRoleAsync(int Id) => throw new NotImplementedException();
user.PasswordHash = PasswordHasher.HashPassword(userDTO.Password);
_dbContext.Users.Add(user);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<UserDTO>(user);
}
else
{
var user = await _dbContext.Users.Where(w => w.Id == userDTO.Id).FirstOrDefaultAsync();
if (user != null)
{
user.UserName = userDTO.UserName;
user.FirstName = userDTO.FirstName;
user.LastName = userDTO.LastName;
user.Email = userDTO.Email;
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<UserDTO>(user);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<RoleDTO> GetRoleAsync(int Id) => throw new NotImplementedException();
public async Task<List<RoleDTO>> GetAllRoleAsync()
{
var retVal = new List<RoleDTO>();
try
{
var roles = await _dbContext.Roles.ToListAsync();
if (roles != null)
{
retVal = _mapper.Map<List<RoleDTO>>(roles);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
public async Task<UserRoleDTO> GetUserRoleAsync(int Id) => throw new NotImplementedException();
public Task<List<UserRoleDTO>> GetAllUserRoleAsync() => throw new NotImplementedException();
public Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
}
}