RoleCheckListHeaderTemplate befejezése új/módosítás

This commit is contained in:
2025-03-28 12:55:10 +01:00
parent f119b196ea
commit ddc898cc2e
11 changed files with 419 additions and 8 deletions
@@ -292,6 +292,37 @@ namespace WorkFlowCheck.API.Controllers
} }
[HttpGet("GetRoleCheckListTemplateHeader/{id}")]
public async Task<ApiResponseDTO<RoleCheckListTemplateHeaderDTO>> GetRoleCheckListTemplateHeader(int id)
{
var retVal = new ApiResponseDTO<RoleCheckListTemplateHeaderDTO>()
{
IsSuccess = true,
};
var roleCheckListTemplateHeaderDTO = await _userService.GetRoleCheckListTemplateHeaderAsync(id);
if (roleCheckListTemplateHeaderDTO != null)
{
if (roleCheckListTemplateHeaderDTO.Id == 0)
{
retVal.IsSuccess = false;
retVal.Errors.Add("No match!");
retVal.Data = roleCheckListTemplateHeaderDTO;
}
else
{
retVal.IsSuccess = true;
retVal.Data = roleCheckListTemplateHeaderDTO;
}
}
else
{
retVal.IsSuccess = false;
retVal.Errors.Add("No data!");
}
return retVal;
}
[HttpGet("GetAllRoleCheckListTemplateHeaders")] [HttpGet("GetAllRoleCheckListTemplateHeaders")]
public async Task<ApiResponseDTO<List<RoleCheckListTemplateHeaderDTO>>> GetAllRoleCheckListTemplateHeaders() public async Task<ApiResponseDTO<List<RoleCheckListTemplateHeaderDTO>>> GetAllRoleCheckListTemplateHeaders()
{ {
@@ -314,5 +345,26 @@ namespace WorkFlowCheck.API.Controllers
return retVal; return retVal;
} }
[HttpPost("UpdateRoleCheckListTemplateHeader")]
public async Task<ApiResponseDTO<RoleCheckListTemplateHeaderDTO>> UpdateRoleCheckListTemplateHeader([FromBody] RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO)
{
var retVal = new ApiResponseDTO<RoleCheckListTemplateHeaderDTO>()
{
IsSuccess = true
};
try
{
var result = await _userService.UpdateRoleCheckListTemplateHeaderAsync(roleCheckListTemplateHeaderDTO);
retVal.Data = result;
}
catch (Exception ex)
{
retVal.IsSuccess = false;
Log.Error(ex.Message);
}
return retVal;
}
} }
} }
@@ -35,4 +35,8 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="logs\" />
</ItemGroup>
</Project> </Project>
@@ -22,8 +22,10 @@ namespace WorkFlowCheck.BL.Services.Interfaces
Task<List<UserRoleDTO>> GetAllUserRoleAsync(); Task<List<UserRoleDTO>> GetAllUserRoleAsync();
Task<UserRoleDTO> UpdateUserRoleAsync(UserRoleDTO userRoleDTO); Task<UserRoleDTO> UpdateUserRoleAsync(UserRoleDTO userRoleDTO);
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync(); Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeaderAsync(int Id);
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync();
Task<RoleCheckListTemplateHeaderDTO> UpdateRoleCheckListTemplateHeaderAsync(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO);
string GenerateJwtToken(UserDTO userDTO); string GenerateJwtToken(UserDTO userDTO);
} }
} }
@@ -340,6 +340,24 @@ namespace WorkFlowCheck.BL.Services
return retVal; return retVal;
} }
public async Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeaderAsync(int Id)
{
var retVal = new RoleCheckListTemplateHeaderDTO();
try
{
var userRole = await _dbContext.RoleCheckListTemplateHeaders.Where(w => w.Id == Id).FirstOrDefaultAsync();
if (userRole != null)
{
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(userRole);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync() public async Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync()
{ {
var retVal = new List<RoleCheckListTemplateHeaderDTO>(); var retVal = new List<RoleCheckListTemplateHeaderDTO>();
@@ -361,5 +379,55 @@ namespace WorkFlowCheck.BL.Services
} }
return retVal; return retVal;
} }
public async Task<RoleCheckListTemplateHeaderDTO> UpdateRoleCheckListTemplateHeaderAsync(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO)
{
var retVal = new RoleCheckListTemplateHeaderDTO();
try
{
if (roleCheckListTemplateHeaderDTO.Id == 0)
{
var roleCheckListTemplateHeader_Exists = await _dbContext.RoleCheckListTemplateHeaders
.Where(w => w.RoleId == roleCheckListTemplateHeaderDTO.RoleId &&
w.CheckListTemplateHeaderId == roleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId)
.FirstOrDefaultAsync();
if (roleCheckListTemplateHeader_Exists == null)
{
var roleCheckListTemplateHeader = new RoleCheckListTemplateHeader();
roleCheckListTemplateHeader.CheckListTemplateHeaderId = roleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId;
roleCheckListTemplateHeader.RoleId = roleCheckListTemplateHeaderDTO.RoleId;
roleCheckListTemplateHeader.Enabled = roleCheckListTemplateHeaderDTO.Enabled;
_dbContext.RoleCheckListTemplateHeaders.Add(roleCheckListTemplateHeader);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(roleCheckListTemplateHeader);
}
else
{
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(roleCheckListTemplateHeader_Exists);
}
}
else
{
var roleCheckListTemplateHeader = await _dbContext.RoleCheckListTemplateHeaders.Where(w => w.Id == roleCheckListTemplateHeaderDTO.Id).FirstOrDefaultAsync();
if (roleCheckListTemplateHeader != null)
{
roleCheckListTemplateHeader.CheckListTemplateHeaderId = roleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId;
roleCheckListTemplateHeader.RoleId = roleCheckListTemplateHeaderDTO.RoleId;
roleCheckListTemplateHeader.Enabled = roleCheckListTemplateHeaderDTO.Enabled;
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<RoleCheckListTemplateHeaderDTO>(roleCheckListTemplateHeader);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
} }
} }
@@ -11,9 +11,9 @@ namespace WorkFlowCheck.Common.DTO
{ {
public int Id { get; set; } public int Id { get; set; }
public int RoleId { get; set; } public int RoleId { get; set; }
public RoleDTO RoleDTO { get; set; } = null!; public RoleDTO? RoleDTO { get; set; } = null!;
public int CheckListTemplateHeaderId { get; set; } public int CheckListTemplateHeaderId { get; set; }
public CheckListTemplateHeaderDTO CheckListTemplateHeaderDTO { get; set; } = null!; public CheckListTemplateHeaderDTO? CheckListTemplateHeaderDTO { get; set; } = null!;
public bool Enabled { get; set; } = false; public bool Enabled { get; set; } = false;
} }
} }
@@ -1,4 +1,119 @@
@page @page
@model WorkFlowCheck.Web.Pages.UserAndRole.RoleCheckListTemplateHeaderEditPageModel @model WorkFlowCheck.Web.Pages.UserAndRole.RoleCheckListTemplateHeaderEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@{ @{
ViewData["Title"] = "Ellenőrzési pont";
var RoleCheckListTemplateHeaderId = Model.RoleCheckListTemplateHeaderDTO.Id;
var urlPost = Url.Page("./RoleCheckListTemplateHeaderEditPage", "Save");
}
<h1>@ViewData["Title"]</h1>
<input type="hidden" id="RoleCheckListTemplateHeaderEditPostUrl" value="@urlPost" />
<div class="card shadow p-4">
<form method="post" id="RoleCheckListTemplateHeaderForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="RoleCheckListTemplateHeaderDTO.Id" />
<div class="mb-3">
<div class="col-md-3">
<label asp-for="RoleCheckListTemplateHeaderDTO.RoleId"></label>
<select asp-for="RoleCheckListTemplateHeaderDTO.RoleId" class="form-control" asp-items="Model.Roles"></select>
<span asp-validation-for="RoleCheckListTemplateHeaderDTO.RoleId" class="text-danger"></span>
</div>
<div class="col-md-3">
<label asp-for="RoleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId"></label>
<select asp-for="RoleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId" class="form-control" asp-items="Model.RoleCheckListTemplateHeaders"></select>
<span asp-validation-for="RoleCheckListTemplateHeaderDTO.CheckListTemplateHeaderId" class="text-danger"></span>
</div>
<div class="col-md-3">
<label asp-for="RoleCheckListTemplateHeaderDTO.Enabled"></label>
<input type="checkbox" asp-for="RoleCheckListTemplateHeaderDTO.Enabled" class="form-check-input" />
<span asp-validation-for="RoleCheckListTemplateHeaderDTO.Enabled" class="text-danger"></span>
</div>
</div>
<div class="mb-3 d-flex justify-content-between">
<button type="button" id="saveRoleCheckListTemplateHeader" 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>
$("#saveRoleCheckListTemplateHeader").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#RoleCheckListTemplateHeaderForm');
const $form = $('#RoleCheckListTemplateHeaderForm');
formData.RoleCheckListTemplateHeaderDTO.Enabled = $('#RoleCheckListTemplateHeaderForm input[name="RoleCheckListTemplateHeaderDTO.Enabled"]').is(':checked');
// console.log(formData);
console.log(formData.RoleCheckListTemplateHeaderDTO);
if ($form.valid())
{
$.ajax({
url: $('#RoleCheckListTemplateHeaderEditPostUrl').val(),
type: 'POST',
headers: {
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.RoleCheckListTemplateHeaderDTO),
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 = $("#RoleCheckListTemplateHeaderForm");
$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,12 +1,75 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.UserAndRole namespace WorkFlowCheck.Web.Pages.UserAndRole
{ {
public class RoleCheckListTemplateHeaderEditPageModel : PageModel public class RoleCheckListTemplateHeaderEditPageModel : PageModel
{ {
public void OnGet() private readonly ILogger<IndexModel> _logger;
private readonly IUserService _userService;
private readonly ICheckListService _checkListService;
[BindProperty]
public RoleCheckListTemplateHeaderDTO RoleCheckListTemplateHeaderDTO { get; set; } = new();
[BindProperty]
public List<SelectListItem> Roles { get; set; }
[BindProperty]
public List<SelectListItem> RoleCheckListTemplateHeaders { get; set; }
public RoleCheckListTemplateHeaderEditPageModel(ILogger<IndexModel> logger, IUserService userService, ICheckListService checkListService)
{ {
_logger = logger;
_userService = userService;
_checkListService = checkListService;
}
public async Task OnGet(int id)
{
await InitSelectItems();
RoleCheckListTemplateHeaderDTO = await _userService.GetRoleCheckListTemplateHeader(id);
}
public async Task<IActionResult> OnPostSave([FromBody] RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO)
{
try
{
var result = await _userService.UpdateRoleCheckListTemplateHeader(roleCheckListTemplateHeaderDTO);
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 });
}
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 checkListTemplateHeaders = await _checkListService.GetAllCheckListTemplateHeaderAsync();
this.RoleCheckListTemplateHeaders = new List<SelectListItem>();
foreach (var checkListTemplateHeader in checkListTemplateHeaders)
{
this.RoleCheckListTemplateHeaders.Add(new SelectListItem() { Value = checkListTemplateHeader.Id.ToString(), Text = checkListTemplateHeader.ShortName });
}
} }
} }
} }
@@ -17,6 +17,7 @@
<th>ID</th> <th>ID</th>
<th>Role name</th> <th>Role name</th>
<th>Template name</th> <th>Template name</th>
<th>Enabled</th>
<th class="text-center">Action</th> <th class="text-center">Action</th>
</tr> </tr>
</thead> </thead>
@@ -25,6 +26,7 @@
<th>ID</th> <th>ID</th>
<th>Role name</th> <th>Role name</th>
<th>Template name</th> <th>Template name</th>
<th>Enabled</th>
<th class="text-center">Action</th> <th class="text-center">Action</th>
</tr> </tr>
</tfoot> </tfoot>
@@ -43,6 +45,22 @@
{ data: "id" }, { data: "id" },
{ data: "roleDTO.roleName" }, { data: "roleDTO.roleName" },
{ data: "checkListTemplateHeaderDTO.description" }, { data: "checkListTemplateHeaderDTO.description" },
{
data: "enabled",
searchable: false,
sortable: false,
className: "text-center",
render: function ( data, type, row ) {
if (data === true) {
return '<input type="checkbox" class="editor-active" disabled checked>';
}
if (data === false) {
return '<input type="checkbox" class="editor-active" disabled>';
}
return data;
}
},
{ data: null, render: function (data, type, row) { { data: null, render: function (data, type, row) {
return renderActionButtons(row.id); return renderActionButtons(row.id);
}} }}
@@ -53,7 +71,7 @@
"visible": false "visible": false
}, },
{ {
"targets": 3, "targets": 4,
"className": "text-center", "className": "text-center",
"width": "10%" "width": "10%"
} }
@@ -1,12 +1,49 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.RazorPages;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.UserAndRole namespace WorkFlowCheck.Web.Pages.UserAndRole
{ {
public class UserRoleEditPageModel : PageModel public class UserRoleEditPageModel : PageModel
{ {
public void OnGet() private readonly ILogger<IndexModel> _logger;
private readonly IUserService _userService;
[BindProperty]
public UserRoleDTO UserRoleDTO { get; set; }
public UserRoleEditPageModel(ILogger<IndexModel> logger, IUserService userService)
{ {
_logger = logger;
_userService = userService;
}
public async Task OnGet(int id)
{
UserRoleDTO = await _userService.GetUserRole(id);
}
public async Task<IActionResult> OnPostSave([FromBody] UserRoleDTO userRoleDTO)
{
try
{
var result = await _userService.UpdateUserRole(userRoleDTO);
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 });
} }
} }
} }
@@ -17,6 +17,9 @@ namespace WorkFlowCheck.Web.Services.Interfaces
Task<List<UserRoleDTO>> GetAllUserRoles(); Task<List<UserRoleDTO>> GetAllUserRoles();
Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO); Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO);
Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeader(int id);
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplates(); Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplates();
Task<ApiResponseDTO<RoleCheckListTemplateHeaderDTO>> UpdateRoleCheckListTemplateHeader(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO);
} }
} }
+50 -1
View File
@@ -196,7 +196,7 @@ namespace WorkFlowCheck.Web.Services
public async Task<UserRoleDTO> GetUserRole(int id) public async Task<UserRoleDTO> GetUserRole(int id)
{ {
string endpoint = $"{_httpClient.BaseAddress}api/UserRole/GetUserRole/{id}"; string endpoint = $"{_httpClient.BaseAddress}api/user/GetUserRole/{id}";
var retVal = new UserRoleDTO(); var retVal = new UserRoleDTO();
try try
{ {
@@ -265,6 +265,27 @@ namespace WorkFlowCheck.Web.Services
} }
} }
public async Task<RoleCheckListTemplateHeaderDTO> GetRoleCheckListTemplateHeader(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/user/GetRoleCheckListTemplateHeader/{id}";
var retVal = new RoleCheckListTemplateHeaderDTO();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<RoleCheckListTemplateHeaderDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplates() public async Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplates()
{ {
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllRoleCheckListTemplateHeaders"; string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllRoleCheckListTemplateHeaders";
@@ -286,5 +307,33 @@ namespace WorkFlowCheck.Web.Services
} }
return retVal; return retVal;
} }
public async Task<ApiResponseDTO<RoleCheckListTemplateHeaderDTO>> UpdateRoleCheckListTemplateHeader(RoleCheckListTemplateHeaderDTO roleCheckListTemplateHeaderDTO)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/user/UpdateRoleCheckListTemplateHeader";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, roleCheckListTemplateHeaderDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<RoleCheckListTemplateHeaderDTO>>(jsonString);
return response ?? new ApiResponseDTO<RoleCheckListTemplateHeaderDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<RoleCheckListTemplateHeaderDTO>
{
IsSuccess = false
};
}
}
} }
} }