User dolgok javítása
This commit is contained in:
@@ -24,7 +24,7 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
{
|
{
|
||||||
IsSuccess = true,
|
IsSuccess = true,
|
||||||
};
|
};
|
||||||
var userDTO = await _userService.GetUser(id);
|
var userDTO = await _userService.GetUserAsync(id);
|
||||||
|
|
||||||
if (userDTO != null)
|
if (userDTO != null)
|
||||||
{
|
{
|
||||||
@@ -49,7 +49,30 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("authenticate")]
|
[HttpGet("GetAllUser")]
|
||||||
|
public async Task<ApiResponseDTO<List<UserDTO>>> GetAllUser()
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<List<UserDTO>>()
|
||||||
|
{
|
||||||
|
IsSuccess = true,
|
||||||
|
};
|
||||||
|
var userDTO = await _userService.GetAllUserAsync();
|
||||||
|
|
||||||
|
if (userDTO != null)
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = true;
|
||||||
|
retVal.Data = userDTO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = false;
|
||||||
|
retVal.Errors.Add("No data!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("Authenticate")]
|
||||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userDTO)
|
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userDTO)
|
||||||
{
|
{
|
||||||
var retVal = new ApiResponseDTO<UserDTO>()
|
var retVal = new ApiResponseDTO<UserDTO>()
|
||||||
|
|||||||
@@ -9,8 +9,21 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IUserService
|
public interface IUserService
|
||||||
{
|
{
|
||||||
Task<UserDTO> GetUser(int Id);
|
Task<UserDTO> GetUserAsync(int Id);
|
||||||
|
Task<List<UserDTO>> GetAllUserAsync();
|
||||||
|
Task<UserDTO> UpdateUserAsync(UserDTO userDTO);
|
||||||
Task<UserDTO> Authenticate(string UserName, string Password);
|
Task<UserDTO> Authenticate(string UserName, string Password);
|
||||||
|
|
||||||
|
Task<RoleDTO> GetRoleAsync(int Id);
|
||||||
|
Task<List<RoleDTO>> GetAllRoleAsync();
|
||||||
|
Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO);
|
||||||
|
|
||||||
|
Task<UserRoleDTO> GetUserRoleAsync(int Id);
|
||||||
|
Task<List<UserRoleDTO>> GetAllUserRoleAsync();
|
||||||
|
Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string GenerateJwtToken(UserDTO userDTO);
|
string GenerateJwtToken(UserDTO userDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
public async Task<UserDTO> GetUser(int Id)
|
public async Task<UserDTO> GetUserAsync(int Id)
|
||||||
{
|
{
|
||||||
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
|
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
|
||||||
|
|
||||||
@@ -48,7 +48,31 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<UserDTO>> GetAllUserAsync()
|
||||||
|
{
|
||||||
|
var retVal = new List<UserDTO>
|
||||||
|
{
|
||||||
|
new UserDTO
|
||||||
|
{
|
||||||
|
RoleDTO = new List<RoleDTO>()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var users = await _dbContext.Users.ToListAsync();
|
||||||
|
if (users != null)
|
||||||
|
{
|
||||||
|
retVal = _mapper.Map<List<UserDTO>>(users);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<UserDTO> Authenticate(string userName, string password)
|
public async Task<UserDTO> Authenticate(string userName, string password)
|
||||||
{
|
{
|
||||||
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
|
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
|
||||||
@@ -120,5 +144,13 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
|
|
||||||
return new JwtSecurityTokenHandler().WriteToken(token);
|
return new JwtSecurityTokenHandler().WriteToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
public Task<List<UserRoleDTO>> GetAllUserRoleAsync() => throw new NotImplementedException();
|
||||||
|
public Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Common.DTO
|
||||||
|
{
|
||||||
|
public class UserRoleDTO
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int? RoleId { get; set; } = 0;
|
||||||
|
public int UserId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user