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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user