CheckListRow edit
This commit is contained in:
@@ -221,5 +221,49 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("GetCheckListRow/{id}")]
|
||||||
|
public async Task<ApiResponseDTO<CheckListRowDTO>> GetCheckListRow(int id)
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<CheckListRowDTO>()
|
||||||
|
{
|
||||||
|
IsSuccess = true,
|
||||||
|
};
|
||||||
|
var checkListRowDTO = await _checkListService.GetCheckListRowAsync(id);
|
||||||
|
|
||||||
|
if (checkListRowDTO != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
retVal.IsSuccess = true;
|
||||||
|
retVal.Data = checkListRowDTO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = false;
|
||||||
|
retVal.Errors.Add("No data!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
public async Task<ApiResponseDTO<CheckListRowDTO>> UpdateCheckListRow([FromBody] CheckListRowDTO CheckListRowDTO)
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<CheckListRowDTO>()
|
||||||
|
{
|
||||||
|
IsSuccess = true
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await _checkListService.UpdateCheckListRowAsync(CheckListRowDTO);
|
||||||
|
retVal.Data = result;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = false;
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,6 +363,60 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<CheckListRowDTO> GetCheckListRowAsync(int id)
|
||||||
|
{
|
||||||
|
var retVal = new CheckListRowDTO();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var res = await _dbContext.CheckListRows
|
||||||
|
.Include(i => i.CheckListTemplateRow)
|
||||||
|
.Where(w => w.Id == id)
|
||||||
|
.AsNoTracking()
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
retVal = _mapper.Map<CheckListRowDTO>(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
public async Task<CheckListRowDTO> UpdateCheckListRowAsync(CheckListRowDTO checkListRowDTO)
|
||||||
|
{
|
||||||
|
var retVal = new CheckListRowDTO() { };
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (checkListRowDTO.Id == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var checkListRow = await _dbContext.CheckListRows
|
||||||
|
.Where(w => w.Id == checkListRowDTO.Id)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
if (checkListRow != null)
|
||||||
|
{
|
||||||
|
checkListRow.Answer = checkListRowDTO.Answer;
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
retVal = _mapper.Map<CheckListRowDTO>(checkListRow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public byte[] CreatePDF(int checkListHeaderId)
|
public byte[] CreatePDF(int checkListHeaderId)
|
||||||
{
|
{
|
||||||
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
|||||||
Task<CheckListTemplateRowDTO> GetCheckListTemplateRowAsync(int id);
|
Task<CheckListTemplateRowDTO> GetCheckListTemplateRowAsync(int id);
|
||||||
Task<CheckListTemplateRowDTO> UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO);
|
Task<CheckListTemplateRowDTO> UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO);
|
||||||
|
|
||||||
|
Task<CheckListRowDTO> GetCheckListRowAsync(int id);
|
||||||
|
Task<CheckListRowDTO> UpdateCheckListRowAsync(CheckListRowDTO checkListRowDTO);
|
||||||
|
|
||||||
byte[] CreatePDF(int checkListHeaderId);
|
byte[] CreatePDF(int checkListHeaderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,93 @@
|
|||||||
@page
|
@page
|
||||||
@model WorkFlowCheck.Web.Pages.CheckList.CheckListRow.CheckListRowEditPageModel
|
@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;
|
||||||
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.Interfaces;
|
||||||
|
|
||||||
namespace WorkFlowCheck.Web.Pages.CheckList.CheckListRow
|
namespace WorkFlowCheck.Web.Pages.CheckList.CheckListRow
|
||||||
{
|
{
|
||||||
public class CheckListRowEditPageModel : PageModel
|
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<CheckListTemplateRowDTO> GetCheckListTemplateRow(int id);
|
||||||
Task<ApiResponseDTO<CheckListTemplateRowDTO>> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO);
|
Task<ApiResponseDTO<CheckListTemplateRowDTO>> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO);
|
||||||
|
|
||||||
|
Task<CheckListRowDTO> GetCheckListRow(int id);
|
||||||
|
Task<ApiResponseDTO<CheckListRowDTO>> UpdateCheckListRow(CheckListRowDTO checkListRowDTO);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user