diff --git a/src/WorkFlowCheck.BL/Services/SyncService.cs b/src/WorkFlowCheck.BL/Services/SyncService.cs index 2f6f47d..0bd085d 100644 --- a/src/WorkFlowCheck.BL/Services/SyncService.cs +++ b/src/WorkFlowCheck.BL/Services/SyncService.cs @@ -212,8 +212,7 @@ namespace WorkFlowCheck.BL.Services var res = await _dbContext.Locations.Where(w => w.Id == LocationDTO.Id).FirstOrDefaultAsync(); if (res != null) { - res = _mapper.Map(LocationDTO); - + res.FullName = LocationDTO.FullName; await _dbContext.SaveChangesAsync(); retVal = _mapper.Map(res); diff --git a/src/WorkFlowCheck.Common/DTO/EquipmentDTO.cs b/src/WorkFlowCheck.Common/DTO/EquipmentDTO.cs index c738bc6..d9d737f 100644 --- a/src/WorkFlowCheck.Common/DTO/EquipmentDTO.cs +++ b/src/WorkFlowCheck.Common/DTO/EquipmentDTO.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,7 +11,13 @@ namespace WorkFlowCheck.Common.DTO public class EquipmentDTO { public int Id { get; set; } + + [Required(ErrorMessage = "A megnevezést megadása kötelező.")] + [DisplayName("Megnevezés")] public string ShortName { get; set; } = null!; + + [Required(ErrorMessage = "Az azonosító megadása kötelező.")] + [DisplayName("Azonosító")] public string EquipmentNumber { get; set; } = null!; } } diff --git a/src/WorkFlowCheck.Common/DTO/LocationDTO.cs b/src/WorkFlowCheck.Common/DTO/LocationDTO.cs index 6f4e74b..7237f7a 100644 --- a/src/WorkFlowCheck.Common/DTO/LocationDTO.cs +++ b/src/WorkFlowCheck.Common/DTO/LocationDTO.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,6 +11,9 @@ namespace WorkFlowCheck.Common.DTO public class LocationDTO { public int Id { get; set; } + + [Required(ErrorMessage = "A megnevezést megadása kötelező.")] + [DisplayName("Megnevezés")] public string FullName { get; set; } = null!; } } diff --git a/src/WorkFlowCheck.Web/Helpers/AspForDataTypeTagHelper.cs b/src/WorkFlowCheck.Web/Helpers/AspForDataTypeTagHelper.cs new file mode 100644 index 0000000..af9484b --- /dev/null +++ b/src/WorkFlowCheck.Web/Helpers/AspForDataTypeTagHelper.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Microsoft.AspNetCore.Razor.TagHelpers; + +namespace WorkFlowCheck.Web.Helpers +{ + [HtmlTargetElement("input", Attributes = "asp-for-datatype")] + public class AspForDataTypeTagHelper : TagHelper + { + [HtmlAttributeName("asp-for-datatype")] + public ModelExpression For { get; set; } + + public override void Process(TagHelperContext context, TagHelperOutput output) + { + if (For == null) return; + + var type = For.ModelExplorer.ModelType; + + string dataType = GetDataTypeString(type); + output.Attributes.SetAttribute("data-type", dataType); + } + + private string GetDataTypeString(Type type) + { + // Nullable esetén nyerjük ki az alaptípust + if (Nullable.GetUnderlyingType(type) is Type underlyingType) + { + type = underlyingType; + } + + if (type == typeof(string)) return "string"; + if (type == typeof(int) || type == typeof(long) || type == typeof(float) || + type == typeof(double) || type == typeof(decimal)) return "number"; + if (type == typeof(bool)) return "bool"; + if (type == typeof(DateTime)) return "date"; + + return "string"; // default fallback + } + + } +} diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml index ab5b443..1c7a0ff 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml @@ -79,7 +79,7 @@ $('#tbEquipmentsPage').on('click', '.delete-btn', function () { const row = table.row($(this).closest('tr')).data(); - deleteEntity(table, '/BaseStock/Equipments/EquipmentPage?handler=DeleteEquipment', row.id); + deleteEntity(table, '/BaseStock/Equipments/EquipmentsPage?handler=DeleteEquipment', row.id); }); } diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml index b0cc1a8..649e0d0 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Locations/LocationsPage.cshtml @@ -17,14 +17,14 @@ ID - Full name + @DisplayNameHelper.GetDisplayName(nameof(LocationDTO.FullName), typeof(LocationDTO)) Action ID - Full name + @DisplayNameHelper.GetDisplayName(nameof(LocationDTO.FullName), typeof(LocationDTO)) Action diff --git a/src/WorkFlowCheck.Web/wwwroot/js/site.js b/src/WorkFlowCheck.Web/wwwroot/js/site.js index 2634dee..a666dc4 100644 --- a/src/WorkFlowCheck.Web/wwwroot/js/site.js +++ b/src/WorkFlowCheck.Web/wwwroot/js/site.js @@ -2,7 +2,11 @@ // for details on configuring this project to bundle and minify static web assets. // Write your JavaScript code. -function parseValue(value) { +function parseValue(value, type = "string") { + if (type === "string") { + return value; + } + if (value === "") return null; // Boolean @@ -23,17 +27,17 @@ function getFormAsNestedObject(formSelector) { formArray.forEach(function (item) { var keys = item.name.split('.'); - var value = parseValue(item.value); + var inputElement = document.querySelector(`[name="${item.name}"]`); + var type = inputElement?.dataset?.type || "string"; // ha nincs data-type, alap: string + var value = parseValue(item.value, type); 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] = {}; } @@ -44,6 +48,7 @@ function getFormAsNestedObject(formSelector) { return result; } + function showConfirmModal(options) { return new Promise(function (resolve) { // Alapértelmezett értékek