diff --git a/src/WorkFlowCheck.API/Controllers/CheckListController.cs b/src/WorkFlowCheck.API/Controllers/CheckListController.cs index 04338f8..eeae34c 100644 --- a/src/WorkFlowCheck.API/Controllers/CheckListController.cs +++ b/src/WorkFlowCheck.API/Controllers/CheckListController.cs @@ -221,5 +221,49 @@ namespace WorkFlowCheck.API.Controllers } return retVal; } + + [HttpGet("GetCheckListRow/{id}")] + public async Task> GetCheckListRow(int id) + { + var retVal = new ApiResponseDTO() + { + 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> UpdateCheckListRow([FromBody] CheckListRowDTO CheckListRowDTO) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true + }; + + try + { + var result = await _checkListService.UpdateCheckListRowAsync(CheckListRowDTO); + retVal.Data = result; + + } + catch (Exception ex) + { + retVal.IsSuccess = false; + Log.Error(ex.Message); + } + return retVal; + } } } diff --git a/src/WorkFlowCheck.BL/Services/CheckListService.cs b/src/WorkFlowCheck.BL/Services/CheckListService.cs index cc5eb6d..1e73dcd 100644 --- a/src/WorkFlowCheck.BL/Services/CheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/CheckListService.cs @@ -363,6 +363,60 @@ namespace WorkFlowCheck.BL.Services return retVal; } + public async Task 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(res); + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } + public async Task 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(checkListRow); + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } + + public byte[] CreatePDF(int checkListHeaderId) { var location = System.Reflection.Assembly.GetEntryAssembly().Location; diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs index 3e1c3b0..45e2a10 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/ICheckListService.cs @@ -23,6 +23,9 @@ namespace WorkFlowCheck.BL.Services.Interfaces Task GetCheckListTemplateRowAsync(int id); Task UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO); + Task GetCheckListRowAsync(int id); + Task UpdateCheckListRowAsync(CheckListRowDTO checkListRowDTO); + byte[] CreatePDF(int checkListHeaderId); } } diff --git a/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml index 0fb9848..aa2edd9 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml @@ -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"); +} +

@ViewData["Title"]

+ + + + +
+
+ + + + + +
+ +
+ @Model.CheckListRow.CheckListTemplateRowDTO?.OperationDescription +
+
+ +
+ + + +
+
+ + + @if (Model.CheckListRow.Photo != null && Model.CheckListRow.Photo.Length > 0) + { + var base64Image = $"data:image/jpeg;base64,{Convert.ToBase64String(Model.CheckListRow.Photo)}"; + + } + + + +
+ +
+ + +
+
+ +
+ +@section Scripts { + } diff --git a/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml.cs index 5287b8a..1fabdc6 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/CheckList/CheckListRow/CheckListRowEditPage.cshtml.cs @@ -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 _logger; + private readonly ICheckListService _checkListService; + private readonly IBaseStockService _baseStockService; + + + [BindProperty] + public CheckListRowDTO CheckListRow { get; set; } + + public CheckListRowEditPageModel(ILogger 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 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 }); } } } diff --git a/src/WorkFlowCheck.Web/Services/CheckListService.cs b/src/WorkFlowCheck.Web/Services/CheckListService.cs index aa356f3..56e4919 100644 --- a/src/WorkFlowCheck.Web/Services/CheckListService.cs +++ b/src/WorkFlowCheck.Web/Services/CheckListService.cs @@ -150,6 +150,56 @@ namespace WorkFlowCheck.Web.Services }; } } + + public async Task GetCheckListRow(int id) + { + string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListRow/{id}"; + var retVal = new CheckListRowDTO(); + try + { + var response = await _httpClient.GetFromJsonAsync>(endpoint); + if (response != null) + { + if (response.IsSuccess) + { + return response.Data; + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + return retVal; + } + public async Task> 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>(jsonString); + + return response ?? new ApiResponseDTO + { + IsSuccess = false, + }; + } + } + catch (Exception ex) + { + // Hiba visszaadása + return new ApiResponseDTO + { + IsSuccess = false + }; + } + } } } diff --git a/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs index 5522b9e..39722d4 100644 --- a/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs @@ -15,5 +15,8 @@ namespace WorkFlowCheck.Web.Services.Interfaces Task GetCheckListTemplateRow(int id); Task> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO); + Task GetCheckListRow(int id); + Task> UpdateCheckListRow(CheckListRowDTO checkListRowDTO); + } }