DisplayNameHelper kifejlesztése

This commit is contained in:
2025-04-04 13:38:07 +02:00
parent 5b1f7fb642
commit 476c9ead4c
5 changed files with 93 additions and 39 deletions
+20 -2
View File
@@ -1,21 +1,39 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace WorkFlowCheck.Common.DTO
{
public class UserDTO
{
public int Id { get; set; }
public string Email { get; set; } = null!;
[Required(ErrorMessage = "Az utónév kötelező.")]
[DisplayName("E-mail")]
public string Email { get; set; } = null!;
[Required(ErrorMessage = "Az utónév kötelező.")]
[DisplayName("Utónév")]
public string FirstName { get; set; } = null!;
[Required(ErrorMessage = "Az vezetéknév kötelező.")]
[DisplayName("Vezetéknév")]
public string LastName { get; set; } = null!;
[Required(ErrorMessage = "A felhasználónév kötelező.")]
[DisplayName("Felhasználó neve")]
public string UserName { get;set; } = null!;
[DisplayName("Jelszó")]
public string Password { get; set; }
public string JwtToken { get; set; } = null!;
[DisplayName("Aktív")]
public bool Active { get; set; }
[DisplayName("NFC belépés")]
public bool NFCActive { get; set; }
public ICollection<RoleDTO>? RoleDTO { get; set; } = new List<RoleDTO>();
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.Common.Helper
{
public static class DisplayNameHelper
{
public static string GetDisplayName(string propertyName, Type modelType)
{
var property = modelType.GetProperty(propertyName);
var displayNameAttribute = property?.GetCustomAttributes(typeof(DisplayNameAttribute), false)
.FirstOrDefault() as DisplayNameAttribute;
return displayNameAttribute?.DisplayName ?? propertyName;
}
}
}
@@ -48,6 +48,16 @@
<input asp-for="UserDTO.LastName" class="form-control" />
<span asp-validation-for="UserDTO.LastName" class="text-danger"></span>
</div>
<div class="col-md-3">
<label asp-for="UserDTO.Active"></label>
<input type="checkbox" asp-for="UserDTO.Active" class="form-check-input" />
<span asp-validation-for="UserDTO.Active" class="text-danger"></span>
</div>
<div class="col-md-3">
<label asp-for="UserDTO.NFCActive"></label>
<input type="checkbox" asp-for="UserDTO.NFCActive" class="form-check-input" />
<span asp-validation-for="UserDTO.NFCActive" 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>
@@ -102,35 +112,13 @@
var formData = getFormAsNestedObject('#UserForm');
const $form = $('#UserForm');
formData.User.RoleDTO=[];
formData.UserDTO.RoleDTO=[];
formData.UserDTO.Active = $('#UserForm input[name="UserDTO.Active"]').is(':checked');
formData.UserDTO.NFCActive = $('#UserForm input[name="UserDTO.NFCActive"]').is(':checked');
if ($form.valid())
{
$.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'
});
}
});
saveEntity(csrfToken, formData.UserDTO, $('#UserEditPostUrl').val());
} else
{
$form[0].reportValidity();
@@ -1,5 +1,7 @@
@page
@model WorkFlowCheck.Web.Pages.UserAndRole.UserPageModel
@using WorkFlowCheck.Common.Helper
@using WorkFlowCheck.Common.DTO
@{
ViewData["Title"] = "Felhasználók";
}
@@ -15,20 +17,24 @@
<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>@DisplayNameHelper.GetDisplayName("Active", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("NFCActive", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("FirstName", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("LastName", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("UserName", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("Email", typeof(UserDTO))</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>@DisplayNameHelper.GetDisplayName("Active", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("NFCActive", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("FirstName", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("LastName", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("UserName", typeof(UserDTO))</th>
<th>@DisplayNameHelper.GetDisplayName("Email", typeof(UserDTO))</th>
<th>Action</th>
</tr>
</tfoot>
@@ -45,6 +51,26 @@
},
columns: [
{ data: "id" },
{
data: "active",
searchable: false,
sortable: false,
className: "text-center",
render: function ( data, type, row ) {
return renderCheckBox(data);
}
},
{
data: "nfcActive",
searchable: false,
sortable: false,
className: "text-center",
render: function ( data, type, row ) {
return renderCheckBox(data);
}
},
{ data: "firstName" },
{ data: "lastName" },
{ data: "userName" },
@@ -59,7 +85,7 @@
"visible": false
},
{
"targets": 5,
"targets": 7,
"className": "text-center",
"width": "10%"
}
@@ -7,13 +7,13 @@ namespace WorkFlowCheck.Web.Services.Interfaces
{
Task<CheckPointDTO> GetCheckPoint(int id);
Task<bool> DeleteCheckpoint(int id);
Task<bool> DeleteCheckPoint(int id);
Task<List<CheckPointDTO>> GetAllCheckPoints();
Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint(CheckPointDTO checkPointDTO);
Task<EquipmentDTO> GetEquipment(int id);
Task<bool> EquipmentLocation(int id);
Task<bool> DeleteEquipment(int id);
Task<List<EquipmentDTO>> GetAllEquipments();
Task<ApiResponseDTO<EquipmentDTO>> UpdateEquipment(EquipmentDTO equipmentDTO);