User továbbgondolása
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
using WorkFlowCheck.BL.Services.Interfaces;
|
using WorkFlowCheck.BL.Services.Interfaces;
|
||||||
@@ -49,8 +49,8 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
[HttpGet("GetAllUser")]
|
[HttpGet("GetAllUsers")]
|
||||||
public async Task<ApiResponseDTO<List<UserDTO>>> GetAllUser()
|
public async Task<ApiResponseDTO<List<UserDTO>>> GetAllUsers()
|
||||||
{
|
{
|
||||||
var retVal = new ApiResponseDTO<List<UserDTO>>()
|
var retVal = new ApiResponseDTO<List<UserDTO>>()
|
||||||
{
|
{
|
||||||
@@ -93,32 +93,32 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
[HttpPost("Authenticate")]
|
[HttpPost("Authenticate")]
|
||||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userDTO)
|
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userSimpleDTO)
|
||||||
{
|
{
|
||||||
var retVal = new ApiResponseDTO<UserDTO>()
|
var retVal = new ApiResponseDTO<UserDTO>()
|
||||||
{
|
{
|
||||||
IsSuccess = true
|
IsSuccess = true
|
||||||
};
|
};
|
||||||
if (string.IsNullOrEmpty(userDTO.UserName) || string.IsNullOrEmpty(userDTO.Password))
|
if (string.IsNullOrEmpty(userSimpleDTO.UserName) || string.IsNullOrEmpty(userSimpleDTO.Password))
|
||||||
{
|
{
|
||||||
retVal.IsSuccess = false;
|
retVal.IsSuccess = false;
|
||||||
retVal.Errors.Add("Nem megfelelő felhasználói név vagy jelszó");
|
retVal.Errors.Add("Nem megfelelo felhasználói név vagy jelszó");
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userDTO_Response = await _userService.Authenticate(userDTO.UserName, userDTO.Password);
|
var userDTO_Response = await _userService.Authenticate(userSimpleDTO.UserName, userSimpleDTO.Password);
|
||||||
if (userDTO_Response != null)
|
if (userDTO_Response != null)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(userDTO_Response.UserName) == false && userDTO_Response.UserName == userDTO.UserName)
|
if (string.IsNullOrEmpty(userDTO_Response.UserName) == false && userDTO_Response.UserName == userSimpleDTO.UserName)
|
||||||
{
|
{
|
||||||
retVal.IsSuccess = true;
|
retVal.IsSuccess = true;
|
||||||
retVal.Data = userDTO_Response;
|
retVal.Data = userDTO_Response;
|
||||||
Log.Information($"Sikeres azonosítás! {userDTO.UserName}");
|
Log.Information($"Sikeres azonosítás! {userSimpleDTO.UserName}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var error = $"Nem megfelelő felhasználó vagy jelszó! {userDTO.UserName}";
|
var error = $"Nem megfelelo felhasználó vagy jelszó! {userSimpleDTO.UserName}";
|
||||||
retVal.IsSuccess = false;
|
retVal.IsSuccess = false;
|
||||||
retVal.Errors.Add(error);
|
retVal.Errors.Add(error);
|
||||||
Log.Information(error);
|
Log.Information(error);
|
||||||
@@ -126,7 +126,7 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var error = $"Nem megfelelő felhasználó vagy jelszó! {userDTO.UserName}";
|
var error = $"Nem megfelelo felhasználó vagy jelszó! {userSimpleDTO.UserName}";
|
||||||
retVal.IsSuccess = false;
|
retVal.IsSuccess = false;
|
||||||
retVal.Errors.Add(error);
|
retVal.Errors.Add(error);
|
||||||
Log.Information(error);
|
Log.Information(error);
|
||||||
@@ -171,8 +171,8 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
[HttpGet("GetAllRole")]
|
[HttpGet("GetAllRoles")]
|
||||||
public async Task<ApiResponseDTO<List<RoleDTO>>> GetAllRole()
|
public async Task<ApiResponseDTO<List<RoleDTO>>> GetAllRoles()
|
||||||
{
|
{
|
||||||
var retVal = new ApiResponseDTO<List<RoleDTO>>()
|
var retVal = new ApiResponseDTO<List<RoleDTO>>()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace WorkFlowCheck.Common.DTO
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Common.DTO
|
||||||
{
|
{
|
||||||
public class UserDTO
|
public class UserDTO
|
||||||
{
|
{
|
||||||
@@ -12,4 +14,9 @@
|
|||||||
public required ICollection<RoleDTO> RoleDTO { get; set; } = new List<RoleDTO>();
|
public required ICollection<RoleDTO> RoleDTO { get; set; } = new List<RoleDTO>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UserSimpleDTO
|
||||||
|
{
|
||||||
|
public string UserName { get; set; } = null!;
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,15 @@
|
|||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label asp-for="UserDTO.UserName" class="form-label">Felhasználónév</label>
|
<label asp-for="UserSimpleDTO.UserName" class="form-label">Felhasználónév</label>
|
||||||
<input asp-for="UserDTO.UserName" class="form-control" />
|
<input asp-for="UserSimpleDTO.UserName" class="form-control" />
|
||||||
<span asp-validation-for="UserDTO.UserName" class="text-danger small"></span>
|
<span asp-validation-for="UserSimpleDTO.UserName" class="text-danger small"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label asp-for="UserDTO.Password" class="form-label">Jelszó</label>
|
<label asp-for="UserSimpleDTO.Password" class="form-label">Jelszó</label>
|
||||||
<input asp-for="UserDTO.Password" type="password" class="form-control" />
|
<input asp-for="UserSimpleDTO.Password" type="password" class="form-control" />
|
||||||
<span asp-validation-for="UserDTO.Password" class="text-danger small"></span>
|
<span asp-validation-for="UserSimpleDTO.Password" class="text-danger small"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-grid">
|
<div class="d-grid">
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace WorkFlowCheck.Web.Pages.Account
|
|||||||
|
|
||||||
private readonly IUserService _userService;
|
private readonly IUserService _userService;
|
||||||
[BindProperty]
|
[BindProperty]
|
||||||
public UserDTO UserDTO { get; set; }
|
public UserDTO UserSimpleDTO { get; set; }
|
||||||
public string ErrorMessage { get; set; }
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
public LoginModel(IUserService userService)
|
public LoginModel(IUserService userService)
|
||||||
@@ -25,7 +25,7 @@ namespace WorkFlowCheck.Web.Pages.Account
|
|||||||
}
|
}
|
||||||
public async Task<IActionResult> OnPostAsync()
|
public async Task<IActionResult> OnPostAsync()
|
||||||
{
|
{
|
||||||
var response = await _userService.Authenticate(UserDTO.UserName, UserDTO.Password);
|
var response = await _userService.Authenticate(UserSimpleDTO.UserName, UserSimpleDTO.Password);
|
||||||
|
|
||||||
if (response.IsSuccess)
|
if (response.IsSuccess)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -141,7 +141,11 @@
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js" integrity="sha384-VFQrHzqBh5qiJIU0uGU5CIW3+OWpdGGJM9LBnGbuIH2mkICcFZ7lPd/AAtI7SNf7" crossorigin="anonymous"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js" integrity="sha384-VFQrHzqBh5qiJIU0uGU5CIW3+OWpdGGJM9LBnGbuIH2mkICcFZ7lPd/AAtI7SNf7" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js" integrity="sha384-/RlQG9uf0M2vcTw3CX7fbqgbj/h8wKxw7C3zu9/GxcBPRKOEcESxaxufwRXqzq6n" crossorigin="anonymous"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js" integrity="sha384-/RlQG9uf0M2vcTw3CX7fbqgbj/h8wKxw7C3zu9/GxcBPRKOEcESxaxufwRXqzq6n" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdn.datatables.net/v/bs5/jq-3.7.0/jszip-3.10.1/dt-2.2.2/af-2.7.0/b-3.2.2/b-colvis-3.2.2/b-html5-3.2.2/b-print-3.2.2/cr-2.0.4/date-1.5.5/fc-5.0.4/fh-4.0.1/kt-2.12.1/r-3.0.4/rg-1.5.1/rr-1.5.0/sc-2.4.3/sb-1.8.2/sp-2.3.3/sl-3.0.0/sr-1.4.1/datatables.min.js" integrity="sha384-10kTwhFyUU637a6/7q0kLBdo8jQWjxteg63DT/K8Sdq/nCDaDAkH+Nq/MIrsp8wc" crossorigin="anonymous"></script>
|
<script src="https://cdn.datatables.net/v/bs5/jq-3.7.0/jszip-3.10.1/dt-2.2.2/af-2.7.0/b-3.2.2/b-colvis-3.2.2/b-html5-3.2.2/b-print-3.2.2/cr-2.0.4/date-1.5.5/fc-5.0.4/fh-4.0.1/kt-2.12.1/r-3.0.4/rg-1.5.1/rr-1.5.0/sc-2.4.3/sb-1.8.2/sp-2.3.3/sl-3.0.0/sr-1.4.1/datatables.min.js" integrity="sha384-10kTwhFyUU637a6/7q0kLBdo8jQWjxteg63DT/K8Sdq/nCDaDAkH+Nq/MIrsp8wc" crossorigin="anonymous"></script>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jquery-validation-unobtrusive@4.0.0/dist/jquery.validate.unobtrusive.min.js"></script>
|
||||||
|
|
||||||
@await RenderSectionAsync("Scripts", required: false)
|
@await RenderSectionAsync("Scripts", required: false)
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,4 +1,83 @@
|
|||||||
@page
|
@page
|
||||||
@model WorkFlowCheck.Web.Pages.UserAndRole.UserEditPageModel
|
@model WorkFlowCheck.Web.Pages.UserAndRole.UserEditPageModel
|
||||||
|
@using Microsoft.AspNetCore.Antiforgery
|
||||||
|
@inject IAntiforgery Antiforgery
|
||||||
@{
|
@{
|
||||||
|
ViewData["Title"] = "Ellenőrzési pont";
|
||||||
|
var UserId = Model.User.Id;
|
||||||
|
var urlPost = Url.Page("./UserEditPage", "Save");
|
||||||
|
}
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
|
||||||
|
<input type="hidden" id="UserEditPostUrl" value="@urlPost" />
|
||||||
|
|
||||||
|
<div class="card shadow p-4">
|
||||||
|
<form method="post" id="UserForm">
|
||||||
|
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
|
||||||
|
<input type="hidden" asp-for="User.Id" />
|
||||||
|
<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>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="User.FirstName"></label>
|
||||||
|
<input asp-for="User.FirstName" class="form-control" />
|
||||||
|
<span asp-validation-for="User.FirstName" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="User.LastName"></label>
|
||||||
|
<input asp-for="User.LastName" class="form-control" />
|
||||||
|
<span asp-validation-for="User.LastName" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 d-flex justify-content-between">
|
||||||
|
<button type="button" id="saveUser" class="btn btn-primary">Mentés</button>
|
||||||
|
<button type="button" class="btn btn-secondary" onclick="history.back()">Mégsem</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script>
|
||||||
|
|
||||||
|
$("#saveUser").click(function () {
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
|
var formData = getFormAsNestedObject('#UserForm');
|
||||||
|
const $form = $('#UserForm');
|
||||||
|
console.log($form);
|
||||||
|
if ($form[0].checkValidity())
|
||||||
|
{
|
||||||
|
$.ajax({
|
||||||
|
url: $('#UserEditPostUrl').val(),
|
||||||
|
type: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': csrfToken,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: JSON.stringify(formData.User),
|
||||||
|
success: function (response) {
|
||||||
|
showMessageModal({
|
||||||
|
title: 'Figyelmem!',
|
||||||
|
message: 'Sikeres mentés.',
|
||||||
|
okText: 'Értettem'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
// Hiba esetén
|
||||||
|
console.error("Hiba: ", error);
|
||||||
|
showMessageModal({
|
||||||
|
title: 'Hiba!',
|
||||||
|
message: 'A mentés NEM sikerült!',
|
||||||
|
okText: 'Értettem'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$form[0].reportValidity();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,27 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
|
||||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||||
{
|
{
|
||||||
public class UserEditPageModel : PageModel
|
public class UserEditPageModel : PageModel
|
||||||
{
|
{
|
||||||
public void OnGet()
|
private readonly ILogger<IndexModel> _logger;
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public UserDTO User { get; set; }
|
||||||
|
|
||||||
|
public UserEditPageModel(ILogger<IndexModel> logger, IUserService userService)
|
||||||
{
|
{
|
||||||
|
_userService = userService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnGet(int id)
|
||||||
|
{
|
||||||
|
User = await _userService.GetUser(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,99 @@
|
|||||||
@page
|
@page
|
||||||
@model WorkFlowCheck.Web.Pages.UserAndRole.UserPageModel
|
@model WorkFlowCheck.Web.Pages.UserAndRole.UserPageModel
|
||||||
@{
|
@{
|
||||||
|
ViewData["Title"] = "Felhasználók";
|
||||||
|
}
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
|
||||||
|
<div class="card shadow p-4">
|
||||||
|
<div class="d-flex justify-content-end">
|
||||||
|
<button id="newUserBtn" class="btn btn-primary float-right new-btn">Új elem hozzáadása</button>
|
||||||
|
</div>
|
||||||
|
<table id="tbUsersPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||||
|
<thead class="table-primary">
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>First Name</th>
|
||||||
|
<th>Last Name</th>
|
||||||
|
<th>User Name</th>
|
||||||
|
<th>E-mail</th>
|
||||||
|
<th class="text-center">Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th>ID</th>
|
||||||
|
<th>First Name</th>
|
||||||
|
<th>Last Name</th>
|
||||||
|
<th>User Name</th>
|
||||||
|
<th>E-mail</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script>
|
||||||
|
const table = new DataTable('#tbUsersPage', {
|
||||||
|
ajax: {
|
||||||
|
url: "@Url.Page("./UserPage", "LoadUsers")",
|
||||||
|
type: "GET",
|
||||||
|
dataSrc : "data"
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{ data: "id" },
|
||||||
|
{ data: "firstName" },
|
||||||
|
{ data: "lastName" },
|
||||||
|
{ data: "userName" },
|
||||||
|
{ data: "email" },
|
||||||
|
{ 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": 5,
|
||||||
|
"className": "text-center",
|
||||||
|
"width": "15%"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
processing:true
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#newUserBtn').on('click', function ()
|
||||||
|
{
|
||||||
|
console.log('New button clicked!"');
|
||||||
|
window.location.href = `@Url.Page("./UserEditPage")?id=0`;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#tbUsersPage').on('click', '.edit-btn', function ()
|
||||||
|
{
|
||||||
|
const row = table.row($(this).closest('tr')).data();
|
||||||
|
window.location.href = `@Url.Page("./UserEditPage")?id=${row.id}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#tbUsersPage').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,26 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using WorkFlowCheck.Web.Services;
|
||||||
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
|
||||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||||
{
|
{
|
||||||
public class UserPageModel : PageModel
|
public class UserPageModel : PageModel
|
||||||
{
|
{
|
||||||
public void OnGet()
|
private readonly ILogger<IndexModel> _logger;
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
public UserPageModel(ILogger<IndexModel> logger, IUserService userService)
|
||||||
{
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_userService = userService;
|
||||||
|
}
|
||||||
|
public async Task OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public async Task<JsonResult> OnGetLoadUsers()
|
||||||
|
{
|
||||||
|
var results = await _userService.GetAllUsers();
|
||||||
|
return new JsonResult(new { data = results });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ namespace WorkFlowCheck.Web.Services.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IUserService
|
public interface IUserService
|
||||||
{
|
{
|
||||||
Task<ApiRequestDTO<UserDTO>> GetUser(int id);
|
Task<UserDTO> GetUser(int id);
|
||||||
Task<ApiRequestDTO<List<UserDTO>>> GetAllUsers();
|
Task<List<UserDTO>> GetAllUsers();
|
||||||
Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO user);
|
Task<UserDTO> UpdateUser(UserDTO user);
|
||||||
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
||||||
|
|
||||||
Task<ApiRequestDTO<RoleDTO>> GetRole(int id);
|
Task<RoleDTO> GetRole(int id);
|
||||||
Task<ApiRequestDTO<List<RoleDTO>>> GetAllRoles();
|
Task<List<RoleDTO>> GetAllRoles();
|
||||||
Task<ApiResponseDTO<RoleDTO>> UpdateRole(RoleDTO role);
|
Task<RoleDTO> UpdateRole(RoleDTO role);
|
||||||
|
|
||||||
Task<ApiRequestDTO<UserRoleDTO>> GetUserRole(int id);
|
Task<UserRoleDTO> GetUserRole(int id);
|
||||||
Task<ApiRequestDTO<List<UserDTO>>> GetAllUserRoles();
|
Task<List<UserDTO>> GetAllUserRoles();
|
||||||
Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRole);
|
Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Serilog;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
using WorkFlowCheck.Web.Services.Interfaces;
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
|
||||||
@@ -15,23 +16,17 @@ namespace WorkFlowCheck.Web.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Az API végpont meghatározása
|
// Az API végpont meghatározása
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/user/authenticate";
|
string endpoint = $"{_httpClient.BaseAddress}api/User/Authenticate";
|
||||||
|
|
||||||
var userDTO = new UserDTO()
|
var userSimpleDTO = new UserSimpleDTO()
|
||||||
{
|
{
|
||||||
Email = "",
|
|
||||||
FirstName = "",
|
|
||||||
LastName = "",
|
|
||||||
Id = 0,
|
|
||||||
UserName = username,
|
UserName = username,
|
||||||
Password = password,
|
Password = password,
|
||||||
JwtToken = "",
|
|
||||||
RoleDTO = new List<RoleDTO>(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// HTTP POST kérés küldése
|
|
||||||
|
|
||||||
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userDTO))
|
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userSimpleDTO))
|
||||||
{
|
{
|
||||||
httpResponseMessage.EnsureSuccessStatusCode();
|
httpResponseMessage.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
@@ -53,5 +48,58 @@ 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()
|
||||||
|
{
|
||||||
|
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 Task<RoleDTO> GetRole(int id) => throw new NotImplementedException();
|
||||||
|
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 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user