Merge branch 'master' of https://tfs.nuvolar.hu:8443/tfs/AtomERP/_git/WorkFlowCheck
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Serilog;
|
||||||
using WorkFlowCheck.BL.Services;
|
using WorkFlowCheck.BL.Services;
|
||||||
using WorkFlowCheck.BL.Services.Interfaces;
|
using WorkFlowCheck.BL.Services.Interfaces;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
@@ -27,8 +28,8 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
if (checkPointListDTO != null)
|
if (checkPointListDTO != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
retVal.IsSuccess = true;
|
retVal.IsSuccess = true;
|
||||||
retVal.Data = checkPointListDTO;
|
retVal.Data = checkPointListDTO;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -134,5 +135,27 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("authenticate")]
|
||||||
|
public async Task<ApiResponseDTO<CheckPointDTO>> UpdateCheckPoint([FromBody] CheckPointDTO checkPointDTO)
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<CheckPointDTO>()
|
||||||
|
{
|
||||||
|
IsSuccess = true
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await _syncService.UpdateCheckPointAsync(checkPointDTO);
|
||||||
|
retVal.Data = result;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = false;
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
|||||||
{
|
{
|
||||||
Task<List<CheckPointDTO>> GetAllCheckPointAsync();
|
Task<List<CheckPointDTO>> GetAllCheckPointAsync();
|
||||||
Task<CheckPointDTO> GetCheckPointAsync(int id);
|
Task<CheckPointDTO> GetCheckPointAsync(int id);
|
||||||
|
Task<CheckPointDTO> UpdateCheckPointAsync(CheckPointDTO checkPointDTO);
|
||||||
Task<List<LocationDTO>> GetAllLocationAsync();
|
Task<List<LocationDTO>> GetAllLocationAsync();
|
||||||
Task<List<EquipmentDTO>> GetAllEquipmentAsync();
|
Task<List<EquipmentDTO>> GetAllEquipmentAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,41 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
public async Task<CheckPointDTO> UpdateCheckPointAsync(CheckPointDTO checkPointDTO)
|
||||||
|
{
|
||||||
|
var retVal = new CheckPointDTO();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (checkPointDTO.Id == 0) //Hozzáadás, ha Id == 0
|
||||||
|
{
|
||||||
|
var checkPoint = _mapper.Map<CheckPoint>(checkPointDTO);
|
||||||
|
_dbContext.CheckPoints.Add(checkPoint);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
retVal = _mapper.Map<CheckPointDTO>(checkPoint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var res = await _dbContext.CheckPoints.Where(w => w.Id == checkPointDTO.Id).FirstOrDefaultAsync();
|
||||||
|
if (res != null)
|
||||||
|
{
|
||||||
|
res.ShortName = checkPointDTO.ShortName;
|
||||||
|
res.Code = checkPointDTO.Code;
|
||||||
|
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
retVal = _mapper.Map<CheckPointDTO>(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
public async Task<List<LocationDTO>> GetAllLocationAsync()
|
public async Task<List<LocationDTO>> GetAllLocationAsync()
|
||||||
{
|
{
|
||||||
var retVal = new List<LocationDTO>();
|
var retVal = new List<LocationDTO>();
|
||||||
|
|||||||
@@ -1,36 +1,44 @@
|
|||||||
@page
|
@page
|
||||||
@model WorkFlowCheck.Web.Pages.BaseStock.CheckPoints.CheckPointEditPageModel
|
@model WorkFlowCheck.Web.Pages.BaseStock.CheckPoints.CheckPointEditPageModel
|
||||||
|
@using Microsoft.AspNetCore.Antiforgery
|
||||||
|
@inject IAntiforgery Antiforgery
|
||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Ellenőrzési pont";
|
ViewData["Title"] = "Ellenőrzési pont";
|
||||||
var checkpointId = Model.CheckPoint.Id;
|
var checkpointId = Model.CheckPoint.Id;
|
||||||
var url = Url.Page("./CheckPointEditPage", "LoadCheckListTemplateRows", new { id = checkpointId });
|
var url = Url.Page("./CheckPointEditPage", "LoadCheckListTemplateRows", new { id = checkpointId });
|
||||||
|
var urlPost = Url.Page("./CheckPointEditPage", "Save");
|
||||||
}
|
}
|
||||||
<h1>@ViewData["Title"]</h1>
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
|
||||||
<input type="hidden" id="checkPointEditUrl" value="@url" />
|
<input type="hidden" id="checkPointEditUrl" value="@url" />
|
||||||
|
<input type="hidden" id="checkPointEditPostUrl" value="@urlPost" />
|
||||||
|
|
||||||
|
<div class="card shadow p-4">
|
||||||
|
<form method="post" id="checkPointForm">
|
||||||
|
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
|
||||||
|
|
||||||
<div>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" id="hiddenCheckPointId" value="@Model.CheckPoint.Id" />
|
<input type="hidden" id="hiddenCheckPointId" value="@Model.CheckPoint.Id" />
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="mb-3">
|
||||||
<label asp-for="CheckPoint.ShortName"></label>
|
<label asp-for="CheckPoint.ShortName"></label>
|
||||||
<input asp-for="CheckPoint.ShortName" class="form-control" />
|
<input asp-for="CheckPoint.ShortName" class="form-control" />
|
||||||
<span asp-validation-for="CheckPoint.ShortName" class="text-danger"></span>
|
<span asp-validation-for="CheckPoint.ShortName" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="mb-3">
|
||||||
<label asp-for="CheckPoint.Code"></label>
|
<label asp-for="CheckPoint.Code"></label>
|
||||||
<input asp-for="CheckPoint.Code" class="form-control" />
|
<input asp-for="CheckPoint.Code" class="form-control" />
|
||||||
<span asp-validation-for="CheckPoint.Code" class="text-danger"></span>
|
<span asp-validation-for="CheckPoint.Code" class="text-danger"></span>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">Mentés</button>
|
<div class="mb-3">
|
||||||
|
<button type="button" id="saveCheckPoint" class="btn btn-primary">Mentés</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-flex justify-content-end">
|
<div class="card shadow p-4">
|
||||||
<button class="btn btn-primary float-right">Új elem hozzáadása</button>
|
<div class="d-flex justify-content-end">
|
||||||
</div>
|
<button class="btn btn-primary float-right">Új elem hozzáadása</button>
|
||||||
<div>
|
</div>
|
||||||
<table id="tbCheckPointsEditPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
<table id="tbCheckPointsEditPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||||
<thead class="table-primary">
|
<thead class="table-primary">
|
||||||
<tr>
|
<tr>
|
||||||
@@ -97,5 +105,34 @@
|
|||||||
const row = table.row($(this).closest('tr')).data();
|
const row = table.row($(this).closest('tr')).data();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
$("#saveCheckPoint").click(function () {
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
|
var formData = getFormAsNestedObject('#checkPointForm');
|
||||||
|
|
||||||
|
console.log(formData);
|
||||||
|
console.log(JSON.stringify(formData.CheckPoint));
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: $('#checkPointEditPostUrl').val(),
|
||||||
|
type: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': csrfToken,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: JSON.stringify(formData.CheckPoint),
|
||||||
|
success: function (response) {
|
||||||
|
// Sikeres válasz esetén
|
||||||
|
alert("Sikeres mentés!");
|
||||||
|
// opcionálisan pl. form reset, redirect stb.
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
// Hiba esetén
|
||||||
|
console.error("Hiba: ", error);
|
||||||
|
alert("Mentés nem sikerült.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
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.Common.DTO;
|
||||||
using WorkFlowCheck.Web.Services.Interfaces;
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
|
||||||
namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints
|
namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints
|
||||||
{
|
{
|
||||||
[Authorize]
|
[Authorize]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
public class CheckPointEditPageModel : PageModel
|
public class CheckPointEditPageModel : PageModel
|
||||||
{
|
{
|
||||||
private readonly ILogger<IndexModel> _logger;
|
private readonly ILogger<IndexModel> _logger;
|
||||||
@@ -30,5 +32,21 @@ namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints
|
|||||||
CheckPoint = await _baseStockService.GetCheckPoint(id);
|
CheckPoint = await _baseStockService.GetCheckPoint(id);
|
||||||
return new JsonResult(new { data = CheckPoint.CheckListTemplateRowDTO });
|
return new JsonResult(new { data = CheckPoint.CheckListTemplateRowDTO });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IActionResult> OnPostSave([FromBody] CheckPointDTO checkPointDTO)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await _baseStockService.UpdateCheckPoint(checkPointDTO);
|
||||||
|
return new JsonResult(new { success = true });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JsonResult(new { success = false });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,11 @@
|
|||||||
ViewData["Title"] = "Ellenőrzési pontok";
|
ViewData["Title"] = "Ellenőrzési pontok";
|
||||||
}
|
}
|
||||||
<h1>@ViewData["Title"]</h1>
|
<h1>@ViewData["Title"]</h1>
|
||||||
<div class="d-flex justify-content-end">
|
|
||||||
<button class="btn btn-primary float-right">Új elem hozzáadása</button>
|
<div class="card shadow p-4">
|
||||||
</div>
|
<div class="d-flex justify-content-end">
|
||||||
<div>
|
<button class="btn btn-primary float-right">Új elem hozzáadása</button>
|
||||||
|
</div>
|
||||||
<table id="tbCheckPointsPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
<table id="tbCheckPointsPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||||
<thead class="table-primary">
|
<thead class="table-primary">
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ builder.Host.UseSerilog();
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
builder.Services.AddSingleton<JwtService>();
|
builder.Services.AddSingleton<JwtService>();
|
||||||
|
builder.Services.AddAntiforgery(options =>
|
||||||
|
{
|
||||||
|
options.HeaderName = "X-CSRF-TOKEN"; // JS API hívásokhoz
|
||||||
|
});
|
||||||
|
|
||||||
var jwtSettings = builder.Configuration.GetSection("Jwt");
|
var jwtSettings = builder.Configuration.GetSection("Jwt");
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,30 @@
|
|||||||
// for details on configuring this project to bundle and minify static web assets.
|
// for details on configuring this project to bundle and minify static web assets.
|
||||||
|
|
||||||
// Write your JavaScript code.
|
// Write your JavaScript code.
|
||||||
|
function getFormAsNestedObject(formSelector) {
|
||||||
|
var formArray = $(formSelector).serializeArray();
|
||||||
|
var result = {};
|
||||||
|
|
||||||
|
formArray.forEach(function (item) {
|
||||||
|
var keys = item.name.split('.');
|
||||||
|
var value = item.value;
|
||||||
|
var current = result;
|
||||||
|
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
var key = keys[i];
|
||||||
|
|
||||||
|
// Ha utolsó kulcs, értéket rendelünk hozzá
|
||||||
|
if (i === keys.length - 1) {
|
||||||
|
current[key] = value;
|
||||||
|
} else {
|
||||||
|
// Ha a következő szint nincs meg, hozzuk létre
|
||||||
|
if (!current[key]) {
|
||||||
|
current[key] = {};
|
||||||
|
}
|
||||||
|
current = current[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user