UserRole is benn van, de még nem tökéletes.
This commit is contained in:
@@ -72,7 +72,7 @@ namespace WorkFlowCheck.API.Controllers
|
||||
return retVal;
|
||||
}
|
||||
[HttpPost("UpdateUser")]
|
||||
public async Task<ApiResponseDTO<UserDTO>> UpdateUser([FromBody] UserDTO UserDTO)
|
||||
public async Task<ApiResponseDTO<UserDTO>> UpdateUser([FromBody] UserDTO userDTO)
|
||||
{
|
||||
var retVal = new ApiResponseDTO<UserDTO>()
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace WorkFlowCheck.API.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
var result = await _userService.UpdateUserAsync(UserDTO);
|
||||
var result = await _userService.UpdateUserAsync(userDTO);
|
||||
retVal.Data = result;
|
||||
|
||||
}
|
||||
@@ -194,7 +194,7 @@ namespace WorkFlowCheck.API.Controllers
|
||||
return retVal;
|
||||
}
|
||||
[HttpPost("UpdateRole")]
|
||||
public async Task<ApiResponseDTO<RoleDTO>> UpdateRole([FromBody] RoleDTO RoleDTO)
|
||||
public async Task<ApiResponseDTO<RoleDTO>> UpdateRole([FromBody] RoleDTO roleDTO)
|
||||
{
|
||||
var retVal = new ApiResponseDTO<RoleDTO>()
|
||||
{
|
||||
@@ -203,7 +203,83 @@ namespace WorkFlowCheck.API.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
var result = await _userService.UpdateRoleAsync(RoleDTO);
|
||||
var result = await _userService.UpdateRoleAsync(roleDTO);
|
||||
retVal.Data = result;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("GetUserRole/{id}")]
|
||||
public async Task<ApiResponseDTO<UserRoleDTO>> GetUserRole(int id)
|
||||
{
|
||||
var retVal = new ApiResponseDTO<UserRoleDTO>()
|
||||
{
|
||||
IsSuccess = true,
|
||||
};
|
||||
var RoleDTO = await _userService.GetUserRoleAsync(id);
|
||||
|
||||
if (RoleDTO != null)
|
||||
{
|
||||
if (RoleDTO.Id == 0)
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
retVal.Errors.Add("No match!");
|
||||
retVal.Data = RoleDTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.IsSuccess = true;
|
||||
retVal.Data = RoleDTO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
retVal.Errors.Add("No data!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
[HttpGet("GetAllUserRoles")]
|
||||
public async Task<ApiResponseDTO<List<UserRoleDTO>>> GetAllUserRoles()
|
||||
{
|
||||
var retVal = new ApiResponseDTO<List<UserRoleDTO>>()
|
||||
{
|
||||
IsSuccess = true,
|
||||
};
|
||||
var RoleDTO = await _userService.GetAllUserRoleAsync();
|
||||
|
||||
if (RoleDTO != null)
|
||||
{
|
||||
retVal.IsSuccess = true;
|
||||
retVal.Data = RoleDTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
retVal.Errors.Add("No data!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
[HttpPost("UpdateUserRole")]
|
||||
public async Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole([FromBody] UserRoleDTO userRoleDTO)
|
||||
{
|
||||
var retVal = new ApiResponseDTO<UserRoleDTO>()
|
||||
{
|
||||
IsSuccess = true
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var result = await _userService.UpdateUserRoleAsync(userRoleDTO);
|
||||
retVal.Data = result;
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace WorkFlowCheck.BL.Mappings
|
||||
{
|
||||
CreateMap<User, UserDTO>().ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.UserRoles.Select(ur => ur.Role)));
|
||||
CreateMap<Role, RoleDTO>();
|
||||
CreateMap<UserRole, UserRoleDTO>()
|
||||
.ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.Role))
|
||||
.ForMember(dest => dest.UserDTO, opt => opt.MapFrom(src => src.User));
|
||||
CreateMap<UserDTO, User>()
|
||||
.ForMember(dest => dest.PasswordHash, opt => opt.MapFrom<PasswordHashResolver>());
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
|
||||
Task<UserRoleDTO> GetUserRoleAsync(int Id);
|
||||
Task<List<UserRoleDTO>> GetAllUserRoleAsync();
|
||||
Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO);
|
||||
Task<UserRoleDTO> UpdateUserRoleAsync(UserRoleDTO userRoleDTO);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -224,10 +224,118 @@ namespace WorkFlowCheck.BL.Services
|
||||
}
|
||||
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();
|
||||
public async Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO)
|
||||
{
|
||||
var retVal = new RoleDTO();
|
||||
try
|
||||
{
|
||||
if (roleDTO.Id == 0)
|
||||
{
|
||||
var role = new Role();
|
||||
role.RoleName = roleDTO.RoleName;
|
||||
|
||||
_dbContext.Roles.Add(role);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
retVal = _mapper.Map<RoleDTO>(role);
|
||||
}
|
||||
else
|
||||
{
|
||||
var role = await _dbContext.Roles.Where(w => w.Id == roleDTO.Id).FirstOrDefaultAsync();
|
||||
|
||||
if (role != null)
|
||||
{
|
||||
role.RoleName += roleDTO.RoleName;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
retVal = _mapper.Map<RoleDTO>(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public async Task<UserRoleDTO> GetUserRoleAsync(int Id)
|
||||
{
|
||||
var retVal = new UserRoleDTO();
|
||||
|
||||
try
|
||||
{
|
||||
var userRole = await _dbContext.UserRoles.Where(w => w.Id == Id).FirstOrDefaultAsync();
|
||||
if (userRole != null)
|
||||
{
|
||||
retVal = _mapper.Map<UserRoleDTO>(userRole);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<List<UserRoleDTO>> GetAllUserRoleAsync()
|
||||
{
|
||||
var retVal = new List<UserRoleDTO>();
|
||||
try
|
||||
{
|
||||
var userRoles = await _dbContext.UserRoles
|
||||
.Include(i => i.User)
|
||||
.Include(i => i.Role)
|
||||
.AsNoTracking()
|
||||
.ToListAsync();
|
||||
if (userRoles != null)
|
||||
{
|
||||
retVal = _mapper.Map<List<UserRoleDTO>>(userRoles);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<UserRoleDTO> UpdateUserRoleAsync(UserRoleDTO userRoleDTO)
|
||||
{
|
||||
var retVal = new UserRoleDTO();
|
||||
try
|
||||
{
|
||||
if (userRoleDTO.Id == 0)
|
||||
{
|
||||
var userRole = new UserRole();
|
||||
userRole.UserId = userRoleDTO.UserId;
|
||||
userRole.RoleId = userRoleDTO.RoleId;
|
||||
|
||||
_dbContext.UserRoles.Add(userRole);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
retVal = _mapper.Map<UserRoleDTO>(userRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
var userRole = await _dbContext.UserRoles.Where(w => w.Id == userRoleDTO.Id).FirstOrDefaultAsync();
|
||||
|
||||
if (userRole != null)
|
||||
{
|
||||
userRole.UserId = userRoleDTO.UserId;
|
||||
userRole.RoleId = userRoleDTO.RoleId;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
retVal = _mapper.Map<UserRoleDTO>(userRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace WorkFlowCheck.Common.DTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int? RoleId { get; set; } = 0;
|
||||
public RoleDTO RoleDTO { get; set; }
|
||||
public int UserId { get; set; }
|
||||
public UserDTO UserDTO { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,93 @@
|
||||
@page
|
||||
@model WorkFlowCheck.Web.Pages.UserAndRole.UserRolePageModel
|
||||
@{
|
||||
ViewData["Title"] = "Felhasználók - szabályok";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<div class="card shadow p-4">
|
||||
<div class="d-flex justify-content-end">
|
||||
<button id="newUserRoleBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új kapcsolat">
|
||||
<i class="bi bi-plus-square"></i>
|
||||
</button>
|
||||
</div>
|
||||
<table id="tbUserRolesPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||
<thead class="table-primary">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>User Name</th>
|
||||
<th>Role Name</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot class="table-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>User Name</th>
|
||||
<th>Role Name</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const table = new DataTable('#tbUserRolesPage', {
|
||||
ajax: {
|
||||
url: "@Url.Page("./UserRolePage", "LoadUserRoles")",
|
||||
type: "GET",
|
||||
dataSrc : "data"
|
||||
},
|
||||
columns: [
|
||||
{ data: "id" },
|
||||
{ data: "userDTO.userName" },
|
||||
{ data: "roleDTO.roleName" },
|
||||
{ data: null, render: function (data, type, row) {
|
||||
return renderActionButtons(row.id);
|
||||
}}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
"targets": 0,
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"targets": 3,
|
||||
"className": "text-center",
|
||||
"width": "10%"
|
||||
}
|
||||
],
|
||||
|
||||
processing:true
|
||||
});
|
||||
|
||||
$('#newUserRoleBtn').on('click', function ()
|
||||
{
|
||||
console.log('New button clicked!"');
|
||||
window.location.href = `@Url.Page("./UserRoleEditPage")?id=0`;
|
||||
});
|
||||
|
||||
$('#tbUserRolesPage').on('click', '.edit-btn', function ()
|
||||
{
|
||||
const row = table.row($(this).closest('tr')).data();
|
||||
window.location.href = `@Url.Page("./UserRoleEditPage")?id=${row.id}`;
|
||||
});
|
||||
|
||||
$('#tbUserRolesPage').on('click', '.delete-btn', function ()
|
||||
{
|
||||
const row = table.row($(this).closest('tr')).data();
|
||||
console.log(row);
|
||||
showConfirmModal({
|
||||
title: 'Törlés megerősítése',
|
||||
message: 'Biztosan törölni szeretnéd ezt az elemet?',
|
||||
okText: 'Törlés',
|
||||
cancelText: 'Mégsem'
|
||||
}).then(function(result) {
|
||||
if(result === 'ok') {
|
||||
console.log('Törlés végrehajtva');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
|
||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||
{
|
||||
public class UserRolePageModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
private readonly IUserService _userService;
|
||||
public UserRolePageModel(ILogger<IndexModel> logger, IUserService userService)
|
||||
{
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public async Task<JsonResult> OnGetLoadUserRoles()
|
||||
{
|
||||
var results = await _userService.GetAllUserRoles();
|
||||
return new JsonResult(new { data = results });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user