UserRole javítása

This commit is contained in:
2025-03-28 13:56:56 +01:00
parent ddc898cc2e
commit 148ea094ce
8 changed files with 135 additions and 10 deletions
@@ -10,17 +10,17 @@ namespace WorkFlowCheck.Common.DTO
{
public int Id { get; set; }
public int CheckListTemplateHeaderId { get; set; }
public CheckListTemplateHeaderDTO CheckListTemplateHeaderDTO { get; set; }
public CheckListTemplateHeaderDTO? CheckListTemplateHeaderDTO { get; set; }
public DateTime DateExecution { get; set; }
public int UserId { get; set; }
public UserDTO UserDTO { get; set; }
public UserDTO? UserDTO { get; set; }
public string ShortName { get; set; } = null!;
public string Description { get; set; } = null!;
public string DocumentNumber { get; set; } = null!;
public Guid GuidNumber { get; set; }
public bool IsStorno { get; set; }
public bool IsEditable { get; set; }
public required ICollection<CheckListRowDTO> CheckListRowDTO { get; set; } = new List<CheckListRowDTO>();
public ICollection<CheckListRowDTO>? CheckListRowDTO { get; set; } = new List<CheckListRowDTO>();
public CheckListHeaderDTO()
{
@@ -11,7 +11,7 @@ namespace WorkFlowCheck.Common.DTO
public int Id { get; set; }
public int CheckListHeaderId { get; set; }
public int CheckListTemplateRowId { get; set; }
public CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; }
public CheckListTemplateRowDTO? CheckListTemplateRowDTO { get; set; }
public string GroupName => $"AnswerGroup_{CheckListTemplateRowDTO?.RowIndex ?? 0}";
public string Answer { get; set; } = null!;
public bool? AnswerYes { get; set; } = null!;
@@ -8,6 +8,6 @@ namespace WorkFlowCheck.Common.DTO
public string ShortName { get; set; } = null!;
public string Description { get; set; } = null!;
public required ICollection<CheckListTemplateRowDTO> CheckListTemplateRowDTO { get; set; } = new List<CheckListTemplateRowDTO>();
public required ICollection<CheckListTemplateRowDTO>? CheckListTemplateRowDTO { get; set; } = new List<CheckListTemplateRowDTO>();
}
}
@@ -6,6 +6,6 @@ namespace WorkFlowCheck.Common.DTO
public int Id { get; set; }
public string ShortName { get; set; }
public string Code { get; set; }
public List<CheckListTemplateRowDTO> CheckListTemplateRowDTO { get; set; } = new List<CheckListTemplateRowDTO>();
public List<CheckListTemplateRowDTO>? CheckListTemplateRowDTO { get; set; } = new List<CheckListTemplateRowDTO>();
}
}
+1 -1
View File
@@ -14,6 +14,6 @@ namespace WorkFlowCheck.Common.DTO
public string UserName { get;set; } = null!;
public string Password { get; set; }
public string JwtToken { get; set; } = null!;
public required ICollection<RoleDTO> RoleDTO { get; set; } = new List<RoleDTO>();
public ICollection<RoleDTO>? RoleDTO { get; set; } = new List<RoleDTO>();
}
}
+2 -2
View File
@@ -11,9 +11,9 @@ namespace WorkFlowCheck.Common.DTO
{
public int Id { get; set; }
public int? RoleId { get; set; } = 0;
public RoleDTO RoleDTO { get; set; }
public RoleDTO? RoleDTO { get; set; }
public int UserId { get; set; }
public UserDTO UserDTO { get; set; }
public UserDTO? UserDTO { get; set; }
}
}
@@ -1,4 +1,108 @@
@page
@model WorkFlowCheck.Web.Pages.UserAndRole.UserRoleEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@{
ViewData["Title"] = "Ellenőrzési pont";
var UserRoleId = Model.UserRoleDTO.Id;
var urlPost = Url.Page("./UserRoleEditPage", "Save");
}
<h1>@ViewData["Title"]</h1>
<input type="hidden" id="UserRoleEditPostUrl" value="@urlPost" />
<div class="card shadow p-4">
<form method="post" id="UserRoleForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="UserRoleDTO.Id" />
<div class="mb-3">
<div class="col-md-3">
<label asp-for="UserRoleDTO.RoleId"></label>
<select asp-for="UserRoleDTO.RoleId" class="form-control" asp-items="Model.Roles"></select>
<span asp-validation-for="UserRoleDTO.RoleId" class="text-danger"></span>
</div>
<div class="col-md-3">
<label asp-for="UserRoleDTO.UserId"></label>
<select asp-for="UserRoleDTO.UserId" class="form-control" asp-items="Model.Users"></select>
<span asp-validation-for="UserRoleDTO.UserId" class="text-danger"></span>
</div>
</div>
<div class="mb-3 d-flex justify-content-between">
<button type="button" id="saveUserRole" 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>
$("#saveUserRole").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#UserRoleForm');
const $form = $('#UserRoleForm');
if ($form.valid())
{
$.ajax({
url: $('#UserRoleEditPostUrl').val(),
type: 'POST',
headers: {
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.UserRoleDTO),
success: function (response) {
// console.log(response);
if (response.success)
{
showMessageModal({
title: 'Figyelmem!',
message: 'Sikeres mentés.',
okText: 'Értettem'
});
}
else
{
showMessageModal({
title: 'Figyelmem, HIBA!',
message: 'Sikertelen 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();
}
});
$(document).ready(function () {
const $form = $("#UserRoleForm");
$form.validate({
errorClass: "text-danger small",
errorPlacement: function (error, element) {
error.appendTo(element.parent());
}
});
// $form.on("submit", function (e) {
// if (!$form.valid()) {
// e.preventDefault(); // Ne küldje be, ha van hiba
// }
// });
});
</script>
}
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
@@ -13,6 +14,10 @@ namespace WorkFlowCheck.Web.Pages.UserAndRole
[BindProperty]
public UserRoleDTO UserRoleDTO { get; set; }
[BindProperty]
public List<SelectListItem> Roles { get; set; }
[BindProperty]
public List<SelectListItem> Users { get; set; }
public UserRoleEditPageModel(ILogger<IndexModel> logger, IUserService userService)
{
@@ -22,6 +27,7 @@ namespace WorkFlowCheck.Web.Pages.UserAndRole
public async Task OnGet(int id)
{
await InitSelectItems();
UserRoleDTO = await _userService.GetUserRole(id);
}
public async Task<IActionResult> OnPostSave([FromBody] UserRoleDTO userRoleDTO)
@@ -45,5 +51,20 @@ namespace WorkFlowCheck.Web.Pages.UserAndRole
return new JsonResult(new { success = false });
}
private async Task InitSelectItems()
{
var roles = await _userService.GetAllRoles();
this.Roles = new List<SelectListItem>();
foreach (var role in roles)
{
this.Roles.Add(new SelectListItem() { Value = role.Id.ToString(), Text = role.RoleName });
}
var users = await _userService.GetAllUsers();
this.Users = new List<SelectListItem>();
foreach (var user in users)
{
this.Users.Add(new SelectListItem() { Value = user.Id.ToString(), Text = user.UserName });
}
}
}
}