Location is.
This commit is contained in:
@@ -1,4 +1,91 @@
|
|||||||
@page
|
@page
|
||||||
@model WorkFlowCheck.Web.Pages.BaseStock.Locations.LocationEditPageModel
|
@model WorkFlowCheck.Web.Pages.BaseStock.Locations.LocationEditPageModel
|
||||||
|
@using Microsoft.AspNetCore.Antiforgery
|
||||||
|
@inject IAntiforgery Antiforgery
|
||||||
@{
|
@{
|
||||||
|
ViewData["Title"] = "Lokáció";
|
||||||
|
var LocationId = Model.LocationDTO.Id;
|
||||||
|
var urlPost = Url.Page("./LocationEditPage", "Save");
|
||||||
|
}
|
||||||
|
<h1>@ViewData["Title"]</h1>
|
||||||
|
|
||||||
|
<input type="hidden" id="LocationEditPostUrl" value="@urlPost" />
|
||||||
|
|
||||||
|
<div class="card shadow p-4">
|
||||||
|
<form method="post" id="LocationForm">
|
||||||
|
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
|
||||||
|
<input type="hidden" asp-for="LocationDTO.Id" />
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="LocationDTO.FullName"></label>
|
||||||
|
<input asp-for="LocationDTO.FullName" class="form-control" />
|
||||||
|
<span asp-validation-for="LocationDTO.FullName" class="text-danger"></span>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 d-flex justify-content-between">
|
||||||
|
<button type="button" id="saveLocation" 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>
|
||||||
|
|
||||||
|
$("#saveLocation").click(function () {
|
||||||
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
|
var formData = getFormAsNestedObject('#LocationForm');
|
||||||
|
const $form = $('#LocationForm');
|
||||||
|
|
||||||
|
console.log(formData.Location);
|
||||||
|
|
||||||
|
if ($form.valid())
|
||||||
|
{
|
||||||
|
$.ajax({
|
||||||
|
url: $('#LocationEditPostUrl').val(),
|
||||||
|
type: 'POST',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': csrfToken,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data: JSON.stringify(formData.LocationDTO),
|
||||||
|
success: function (response) {
|
||||||
|
showMessageModal({
|
||||||
|
title: 'Figyelmem!',
|
||||||
|
message: 'Sikeres mentés.',
|
||||||
|
okText: 'Értettem'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function (xhr, status, error) {
|
||||||
|
// Hiba esetén
|
||||||
|
console.error("Hiba: ", error);
|
||||||
|
showMessageModal({
|
||||||
|
title: 'Hiba!',
|
||||||
|
message: 'A mentés NEM sikerült!',
|
||||||
|
okText: 'Értettem'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
$form[0].reportValidity();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
const $form = $("#LocationForm");
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorClass: "text-danger small",
|
||||||
|
errorPlacement: function (error, element) {
|
||||||
|
error.appendTo(element.parent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// $form.on("submit", function (e) {
|
||||||
|
// if (!$form.valid()) {
|
||||||
|
// e.preventDefault(); // Ne küldje be, ha van hiba
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
</script>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,49 @@
|
|||||||
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.Web.Services.Interfaces;
|
||||||
|
|
||||||
namespace WorkFlowCheck.Web.Pages.BaseStock.Locations
|
namespace WorkFlowCheck.Web.Pages.BaseStock.Locations
|
||||||
{
|
{
|
||||||
public class LocationEditPageModel : PageModel
|
public class LocationEditPageModel : PageModel
|
||||||
{
|
{
|
||||||
public void OnGet()
|
private readonly ILogger<IndexModel> _logger;
|
||||||
|
private readonly IBaseStockService _baseStockService;
|
||||||
|
|
||||||
|
[BindProperty]
|
||||||
|
public LocationDTO LocationDTO { get; set; }
|
||||||
|
|
||||||
|
public LocationEditPageModel(ILogger<IndexModel> logger, IBaseStockService baseStockService)
|
||||||
{
|
{
|
||||||
|
_baseStockService = baseStockService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task OnGet(int id)
|
||||||
|
{
|
||||||
|
LocationDTO = await _baseStockService.GetLocation(id);
|
||||||
|
}
|
||||||
|
public async Task<IActionResult> OnPostSave([FromBody] LocationDTO LocationDTO)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = await _baseStockService.UpdateLocation(LocationDTO);
|
||||||
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
<div class="card shadow p-4">
|
<div class="card shadow p-4">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
<button class="btn btn-primary float-right">Új elem hozzáadása</button>
|
<button id="newLocationBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új lokáció">
|
||||||
|
<i class="bi bi-plus-square"></i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<table id="tbLocationsPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
<table id="tbLocationsPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||||
<thead class="table-primary">
|
<thead class="table-primary">
|
||||||
@@ -58,6 +60,11 @@
|
|||||||
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
|
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#newLocationBtn').on('click', function ()
|
||||||
|
{
|
||||||
|
window.location.href = `@Url.Page("/BaseStock/Locations/LocationEditPage")?id=0`;
|
||||||
|
});
|
||||||
|
|
||||||
$('#tbLocationsPage').on('click', '.edit-btn', function ()
|
$('#tbLocationsPage').on('click', '.edit-btn', function ()
|
||||||
{
|
{
|
||||||
const row = table.row($(this).closest('tr')).data();
|
const row = table.row($(this).closest('tr')).data();
|
||||||
|
|||||||
Reference in New Issue
Block a user