User továbbgondolása
This commit is contained in:
@@ -1,4 +1,83 @@
|
||||
@page
|
||||
@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.RazorPages;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
|
||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||
{
|
||||
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
|
||||
@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.RazorPages;
|
||||
using WorkFlowCheck.Web.Services;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
|
||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||
{
|
||||
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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user