CheckListRow edit

This commit is contained in:
2025-03-28 17:35:29 +01:00
parent 728b6a8a9e
commit 77796f3247
7 changed files with 286 additions and 1 deletions
@@ -1,4 +1,93 @@
@page
@model WorkFlowCheck.Web.Pages.CheckList.CheckListRow.CheckListRowEditPageModel
@using Microsoft.AspNetCore.Antiforgery
@inject IAntiforgery Antiforgery
@{
ViewData["Title"] = "Ellenőrzési pont";
var checkListrowId = Model.CheckListRow.Id;
var url = Url.Page("./CheckListRowEditPage", "LoadCheckListRows", new { id = checkListrowId });
var urlPost = Url.Page("./CheckListRowEditPage", "Save");
}
<h1>@ViewData["Title"]</h1>
<input type="hidden" id="checkListRowEditUrl" value="@url" />
<input type="hidden" id="checkListRowEditPostUrl" value="@urlPost" />
<div class="card shadow p-4">
<form method="post" id="checkListRowForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="CheckListRow.Id" />
<input type="hidden" asp-for="CheckListRow.CheckListHeaderId" />
<input type="hidden" asp-for="CheckListRow.GuidNumber" />
<input type="hidden" asp-for="CheckListRow.CheckListTemplateRowId" />
<div class="row mb-3">
<label class="form-label">Leírás</label>
<div class="form-control" style="white-space: pre-wrap;">
@Model.CheckListRow.CheckListTemplateRowDTO?.OperationDescription
</div>
</div>
<div class="row mb-3">
<label asp-for="CheckListRow.Answer"></label>
<input asp-for="CheckListRow.Answer" class="form-control" />
<span asp-validation-for="CheckListRow.Answer" class="text-danger"></span>
</div>
<div class="row mb-3">
<label asp-for="CheckListRow.Photo"></label>
@if (Model.CheckListRow.Photo != null && Model.CheckListRow.Photo.Length > 0)
{
var base64Image = $"data:image/jpeg;base64,{Convert.ToBase64String(Model.CheckListRow.Photo)}";
<img src="@base64Image" width="150" height="100" style="object-fit: cover; display: block; margin-bottom: 10px;" />
}
<input asp-for="CheckListRow.Photo" type="file" class="form-control" />
<span asp-validation-for="CheckListRow.Photo" class="text-danger"></span>
</div>
<div class="mb-3">
<button type="button" id="saveCheckListRow" 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>
$("#saveCheckListRow").click(function () {
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
var formData = getFormAsNestedObject('#checkListRowForm');
$.ajax({
url: $('#checkListRowEditPostUrl').val(),
type: 'POST',
headers: {
'X-CSRF-TOKEN': csrfToken,
'Content-Type': 'application/json'
},
data: JSON.stringify(formData.CheckListRow),
success: function (response) {
// showMessageModal({
// title: 'Figyelmem!',
// message: 'Sikeres mentés.',
// okText: 'Értettem'
// });
history.back();
},
error: function (xhr, status, error) {
// Hiba esetén
console.error("Hiba: ", error);
showMessageModal({
title: 'Hiba!',
message: 'A mentés NEM sikerült!',
okText: 'Értettem'
});
}
});
});
</script>
}
@@ -1,12 +1,54 @@
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;
namespace WorkFlowCheck.Web.Pages.CheckList.CheckListRow
{
public class CheckListRowEditPageModel : PageModel
{
public void OnGet()
private readonly ILogger<IndexModel> _logger;
private readonly ICheckListService _checkListService;
private readonly IBaseStockService _baseStockService;
[BindProperty]
public CheckListRowDTO CheckListRow { get; set; }
public CheckListRowEditPageModel(ILogger<IndexModel> logger, ICheckListService checkListService, IBaseStockService baseStockService)
{
_checkListService = checkListService;
_baseStockService = baseStockService;
_logger = logger;
}
public async Task OnGet(int id)
{
CheckListRow = await _checkListService.GetCheckListRow(id);
}
public async Task<IActionResult> OnPostSave([FromBody] CheckListRowDTO checkListRowDTO)
{
try
{
var result = await _checkListService.UpdateCheckListRow(checkListRowDTO);
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 });
}
}
}
@@ -150,6 +150,56 @@ namespace WorkFlowCheck.Web.Services
};
}
}
public async Task<CheckListRowDTO> GetCheckListRow(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListRow/{id}";
var retVal = new CheckListRowDTO();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<CheckListRowDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<CheckListRowDTO>> UpdateCheckListRow(CheckListRowDTO checkListRowDTO)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/CheckList/UpdateCheckListRow";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkListRowDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<CheckListRowDTO>>(jsonString);
return response ?? new ApiResponseDTO<CheckListRowDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<CheckListRowDTO>
{
IsSuccess = false
};
}
}
}
}
@@ -15,5 +15,8 @@ namespace WorkFlowCheck.Web.Services.Interfaces
Task<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id);
Task<ApiResponseDTO<CheckListTemplateRowDTO>> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO);
Task<CheckListRowDTO> GetCheckListRow(int id);
Task<ApiResponseDTO<CheckListRowDTO>> UpdateCheckListRow(CheckListRowDTO checkListRowDTO);
}
}