Role lista hozzáadása
This commit is contained in:
@@ -5,6 +5,6 @@
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Welcome</h1>
|
||||
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
||||
<h1 class="display-4">Üdvözlöm!</h1>
|
||||
<p>WorkFlowCheck Tablet & WEB & API rendszer</a>.</p>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,90 @@
|
||||
@page
|
||||
@model WorkFlowCheck.Web.Pages.UserAndRole.RolePageModel
|
||||
@{
|
||||
ViewData["Title"] = "Szabályok";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<div class="card shadow p-4">
|
||||
<div class="d-flex justify-content-end">
|
||||
<button id="newRoleBtn" class="btn btn-primary float-right new-btn">Új elem hozzáadása</button>
|
||||
</div>
|
||||
<table id="tbRolesPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||
<thead class="table-primary">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Role Name</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot class="table-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Role Name</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const table = new DataTable('#tbRolesPage', {
|
||||
ajax: {
|
||||
url: "@Url.Page("./RolePage", "LoadRoles")",
|
||||
type: "GET",
|
||||
dataSrc : "data"
|
||||
},
|
||||
columns: [
|
||||
{ data: "id" },
|
||||
{ data: "roleName" },
|
||||
{ data: null, render: function (data, type, row) {
|
||||
return `<button class="btn btn-primary edit-btn" data-id="${row.id}">Módosítás</button>
|
||||
<button class="btn btn-danger delete-btn" data-id="${row.id}">Törlés</button>
|
||||
`;
|
||||
}}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
"targets": 0,
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"targets": 2,
|
||||
"className": "text-center",
|
||||
"width": "15%"
|
||||
}
|
||||
],
|
||||
|
||||
processing:true
|
||||
});
|
||||
|
||||
$('#newRoleBtn').on('click', function ()
|
||||
{
|
||||
console.log('New button clicked!"');
|
||||
window.location.href = `@Url.Page("./RoleEditPage")?id=0`;
|
||||
});
|
||||
|
||||
$('#tbRolesPage').on('click', '.edit-btn', function ()
|
||||
{
|
||||
const row = table.row($(this).closest('tr')).data();
|
||||
window.location.href = `@Url.Page("./RoleEditPage")?id=${row.id}`;
|
||||
});
|
||||
|
||||
$('#tbRolesPage').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 RolePageModel : PageModel
|
||||
{
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
private readonly IUserService _userService;
|
||||
public RolePageModel(ILogger<IndexModel> logger, IUserService userService)
|
||||
{
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
}
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public async Task<JsonResult> OnGetLoadRoles()
|
||||
{
|
||||
var results = await _userService.GetAllRoles();
|
||||
return new JsonResult(new { data = results });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,27 @@
|
||||
<form method="post" id="UserForm">
|
||||
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
|
||||
<input type="hidden" asp-for="User.Id" />
|
||||
<input type="hidden" asp-for="User.Password" value="" />
|
||||
<input type="hidden" asp-for="User.JwtToken" value="" />
|
||||
<input type="hidden" asp-for="User.RoleDTO" value="" />
|
||||
<div class="mb-3">
|
||||
<label asp-for="User.UserName"></label>
|
||||
<input asp-for="User.UserName" class="form-control" />
|
||||
<span asp-validation-for="User.UserName" class="text-danger"></span>
|
||||
</div>
|
||||
@if (Model.User.Id == 0)
|
||||
{
|
||||
<div class="mb-3">
|
||||
<label asp-for="User.Password"></label>
|
||||
<input asp-for="User.Password" class="form-control" type="password" />
|
||||
<span asp-validation-for="User.Password" class="text-danger"></span>
|
||||
</div>
|
||||
}
|
||||
<div class="mb-3">
|
||||
<label asp-for="User.Email"></label>
|
||||
<input asp-for="User.Email" class="form-control" />
|
||||
<span asp-validation-for="User.Email" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="User.FirstName"></label>
|
||||
<input asp-for="User.FirstName" class="form-control" />
|
||||
@@ -45,6 +61,8 @@
|
||||
var formData = getFormAsNestedObject('#UserForm');
|
||||
const $form = $('#UserForm');
|
||||
|
||||
formData.User.RoleDTO=[];
|
||||
|
||||
if ($form.valid())
|
||||
{
|
||||
$.ajax({
|
||||
@@ -78,7 +96,7 @@
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
const $form = $("#userForm");
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Serilog;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.Web.Services;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
|
||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||
@@ -23,5 +25,26 @@ namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||
{
|
||||
User = await _userService.GetUser(id);
|
||||
}
|
||||
public async Task<IActionResult> OnPostSave([FromBody] UserDTO userDTO)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _userService.UpdateUser(userDTO);
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
return new JsonResult(new { success = true });
|
||||
}
|
||||
else
|
||||
{
|
||||
return new JsonResult(new { success = false });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
|
||||
return new JsonResult(new { success = false });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@ namespace WorkFlowCheck.Web.Services.Interfaces
|
||||
{
|
||||
Task<UserDTO> GetUser(int id);
|
||||
Task<List<UserDTO>> GetAllUsers();
|
||||
Task<UserDTO> UpdateUser(UserDTO user);
|
||||
Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO userDTO);
|
||||
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
||||
|
||||
Task<RoleDTO> GetRole(int id);
|
||||
Task<List<RoleDTO>> GetAllRoles();
|
||||
Task<RoleDTO> UpdateRole(RoleDTO role);
|
||||
Task<ApiResponseDTO<RoleDTO>> UpdateRole(RoleDTO roleDTO);
|
||||
|
||||
Task<UserRoleDTO> GetUserRole(int id);
|
||||
Task<List<UserDTO>> GetAllUserRoles();
|
||||
Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole);
|
||||
Task<List<UserRoleDTO>> GetAllUserRoles();
|
||||
Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,78 @@ namespace WorkFlowCheck.Web.Services
|
||||
public UserService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public async Task<UserDTO> GetUser(int id)
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetUser/{id}";
|
||||
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<List<UserDTO>> GetAllUsers()
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUsers";
|
||||
var retVal = new List<UserDTO>();
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO userDTO)
|
||||
{
|
||||
try
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/user/updateUser";
|
||||
|
||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userDTO))
|
||||
{
|
||||
httpResponseMessage.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserDTO>>(jsonString);
|
||||
|
||||
return response ?? new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Hiba visszaadása
|
||||
return new ApiResponseDTO<UserDTO>
|
||||
{
|
||||
IsSuccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password)
|
||||
{
|
||||
try
|
||||
@@ -49,15 +121,14 @@ namespace WorkFlowCheck.Web.Services
|
||||
}
|
||||
}
|
||||
|
||||
public Task<ApiRequestDTO<List<RoleDTO>>> GetAllRoles() => throw new NotImplementedException();
|
||||
public Task<ApiRequestDTO<List<UserDTO>>> GetAllUserRoles() => throw new NotImplementedException();
|
||||
public async Task<List<UserDTO>> GetAllUsers()
|
||||
|
||||
public async Task<RoleDTO> GetRole(int id)
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUsers";
|
||||
var retVal = new List<UserDTO>();
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/Role/GetRole/{id}";
|
||||
var retVal = new RoleDTO();
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<RoleDTO>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
@@ -72,15 +143,64 @@ namespace WorkFlowCheck.Web.Services
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<List<RoleDTO>> GetAllRoles()
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllRoles";
|
||||
var retVal = new List<RoleDTO>();
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<RoleDTO>>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<ApiResponseDTO<RoleDTO>> UpdateRole(RoleDTO roleDTO)
|
||||
{
|
||||
try
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/user/updateRole";
|
||||
|
||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, roleDTO))
|
||||
{
|
||||
httpResponseMessage.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var response = JsonConvert.DeserializeObject<ApiResponseDTO<RoleDTO>>(jsonString);
|
||||
|
||||
return response ?? new ApiResponseDTO<RoleDTO>
|
||||
{
|
||||
IsSuccess = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Hiba visszaadása
|
||||
return new ApiResponseDTO<RoleDTO>
|
||||
{
|
||||
IsSuccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public Task<RoleDTO> GetRole(int id) => throw new NotImplementedException();
|
||||
public async Task<UserDTO> GetUser(int id)
|
||||
|
||||
public async Task<UserRoleDTO> GetUserRole(int id)
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetUser/{id}";
|
||||
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/UserRole/GetUserRole/{id}";
|
||||
var retVal = new UserRoleDTO();
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserRoleDTO>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
@@ -95,11 +215,55 @@ namespace WorkFlowCheck.Web.Services
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public Task<UserRoleDTO> GetUserRole(int id) => throw new NotImplementedException();
|
||||
public Task<RoleDTO> UpdateRole(RoleDTO role) => throw new NotImplementedException();
|
||||
public Task<UserDTO> UpdateUser(UserDTO user) => throw new NotImplementedException();
|
||||
public Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole) => throw new NotImplementedException();
|
||||
Task<List<RoleDTO>> IUserService.GetAllRoles() => throw new NotImplementedException();
|
||||
Task<List<UserDTO>> IUserService.GetAllUserRoles() => throw new NotImplementedException();
|
||||
public async Task<List<UserRoleDTO>> GetAllUserRoles()
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUserRoles";
|
||||
var retVal = new List<UserRoleDTO>();
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserRoleDTO>>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
public async Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO)
|
||||
{
|
||||
try
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/user/updateUserRole";
|
||||
|
||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userRoleDTO))
|
||||
{
|
||||
httpResponseMessage.EnsureSuccessStatusCode();
|
||||
|
||||
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserRoleDTO>>(jsonString);
|
||||
|
||||
return response ?? new ApiResponseDTO<UserRoleDTO>
|
||||
{
|
||||
IsSuccess = false,
|
||||
};
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Hiba visszaadása
|
||||
return new ApiResponseDTO<UserRoleDTO>
|
||||
{
|
||||
IsSuccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user