CheckListRow edit
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user