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 namespace WorkFlowCheck.Common.DTO
{ {
public class UserDTO public class UserDTO
{ {
public int Id { get; set; } public int Id { get; set; }
public string Email { get; set; } = null!;
[Required(ErrorMessage = "Az utónév kötelező.")] [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!; public string FirstName { get; set; } = null!;
[Required(ErrorMessage = "Az vezetéknév kötelező.")] [Required(ErrorMessage = "Az vezetéknév kötelező.")]
[DisplayName("Vezetéknév")]
public string LastName { get; set; } = null!; public string LastName { get; set; } = null!;
[Required(ErrorMessage = "A felhasználónév kötelező.")] [Required(ErrorMessage = "A felhasználónév kötelező.")]
[DisplayName("Felhasználó neve")]
public string UserName { get;set; } = null!; public string UserName { get;set; } = null!;
[DisplayName("Jelszó")]
public string Password { get; set; } public string Password { get; set; }
public string JwtToken { get; set; } = null!; public string JwtToken { get; set; } = null!;
[DisplayName("Aktív")]
public bool Active { get; set; } public bool Active { get; set; }
[DisplayName("NFC belépés")]
public bool NFCActive { get; set; } public bool NFCActive { get; set; }
public ICollection<RoleDTO>? RoleDTO { get; set; } = new List<RoleDTO>(); 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" /> <input asp-for="UserDTO.LastName" class="form-control" />
<span asp-validation-for="UserDTO.LastName" class="text-danger"></span> <span asp-validation-for="UserDTO.LastName" class="text-danger"></span>
</div> </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"> <div class="mb-3 d-flex justify-content-between">
<button type="button" id="saveUser" class="btn btn-primary">Mentés</button> <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> <button type="button" class="btn btn-secondary" onclick="history.back()">Mégsem</button>
@@ -102,35 +112,13 @@
var formData = getFormAsNestedObject('#UserForm'); var formData = getFormAsNestedObject('#UserForm');
const $form = $('#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()) if ($form.valid())
{ {
$.ajax({ saveEntity(csrfToken, formData.UserDTO, $('#UserEditPostUrl').val());
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 } else
{ {
$form[0].reportValidity(); $form[0].reportValidity();
@@ -1,5 +1,7 @@
@page @page
@model WorkFlowCheck.Web.Pages.UserAndRole.UserPageModel @model WorkFlowCheck.Web.Pages.UserAndRole.UserPageModel
@using WorkFlowCheck.Common.Helper
@using WorkFlowCheck.Common.DTO
@{ @{
ViewData["Title"] = "Felhasználók"; ViewData["Title"] = "Felhasználók";
} }
@@ -15,20 +17,24 @@
<thead class="table-primary"> <thead class="table-primary">
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>First Name</th> <th>@DisplayNameHelper.GetDisplayName("Active", typeof(UserDTO))</th>
<th>Last Name</th> <th>@DisplayNameHelper.GetDisplayName("NFCActive", typeof(UserDTO))</th>
<th>User Name</th> <th>@DisplayNameHelper.GetDisplayName("FirstName", typeof(UserDTO))</th>
<th>E-mail</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> <th class="text-center">Action</th>
</tr> </tr>
</thead> </thead>
<tfoot class="table-light"> <tfoot class="table-light">
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>First Name</th> <th>@DisplayNameHelper.GetDisplayName("Active", typeof(UserDTO))</th>
<th>Last Name</th> <th>@DisplayNameHelper.GetDisplayName("NFCActive", typeof(UserDTO))</th>
<th>User Name</th> <th>@DisplayNameHelper.GetDisplayName("FirstName", typeof(UserDTO))</th>
<th>E-mail</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> <th>Action</th>
</tr> </tr>
</tfoot> </tfoot>
@@ -45,6 +51,26 @@
}, },
columns: [ columns: [
{ data: "id" }, { 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: "firstName" },
{ data: "lastName" }, { data: "lastName" },
{ data: "userName" }, { data: "userName" },
@@ -59,7 +85,7 @@
"visible": false "visible": false
}, },
{ {
"targets": 5, "targets": 7,
"className": "text-center", "className": "text-center",
"width": "10%" "width": "10%"
} }
@@ -7,13 +7,13 @@ namespace WorkFlowCheck.Web.Services.Interfaces
{ {
Task<CheckPointDTO> GetCheckPoint(int id); Task<CheckPointDTO> GetCheckPoint(int id);
Task<bool> DeleteCheckpoint(int id); Task<bool> DeleteCheckPoint(int id);
Task<List<CheckPointDTO>> GetAllCheckPoints(); Task<List<CheckPointDTO>> GetAllCheckPoints();
Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint(CheckPointDTO checkPointDTO); Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint(CheckPointDTO checkPointDTO);
Task<EquipmentDTO> GetEquipment(int id); Task<EquipmentDTO> GetEquipment(int id);
Task<bool> EquipmentLocation(int id); Task<bool> DeleteEquipment(int id);
Task<List<EquipmentDTO>> GetAllEquipments(); Task<List<EquipmentDTO>> GetAllEquipments();
Task<ApiResponseDTO<EquipmentDTO>> UpdateEquipment(EquipmentDTO equipmentDTO); Task<ApiResponseDTO<EquipmentDTO>> UpdateEquipment(EquipmentDTO equipmentDTO);