diff --git a/src/WorkFlowCheck.API/Controllers/CheckListController.cs b/src/WorkFlowCheck.API/Controllers/CheckListController.cs index 25ad139..6015773 100644 --- a/src/WorkFlowCheck.API/Controllers/CheckListController.cs +++ b/src/WorkFlowCheck.API/Controllers/CheckListController.cs @@ -196,5 +196,26 @@ namespace WorkFlowCheck.API.Controllers return retVal; } + [HttpPost("UpdateCheckListTemplateRow")] + public async Task> UpdateCheckListTemplateRow([FromBody] CheckListTemplateRowDTO CheckListTemplateRowDTO) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true + }; + + try + { + var result = await _checkListService.UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO); + retVal.Data = result; + + } + catch (Exception ex) + { + retVal.IsSuccess = false; + Log.Error(ex.Message); + } + return retVal; + } } } diff --git a/src/WorkFlowCheck.API/Controllers/SyncController.cs b/src/WorkFlowCheck.API/Controllers/SyncController.cs index 11f0fbc..4adf57f 100644 --- a/src/WorkFlowCheck.API/Controllers/SyncController.cs +++ b/src/WorkFlowCheck.API/Controllers/SyncController.cs @@ -16,6 +16,31 @@ namespace WorkFlowCheck.API.Controllers _syncService = syncService; } + + + [HttpGet("GetCheckPoint/{id}")] + public async Task> GetCheckpointAsync(int id) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true, + }; + var checkPointListDTO = await _syncService.GetCheckPointAsync(id); + + if (checkPointListDTO != null) + { + + retVal.IsSuccess = true; + retVal.Data = checkPointListDTO; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + + return retVal; + } [HttpGet("GetAllCheckPoints")] public async Task>> GetAllCheckpointsAsync() { @@ -39,9 +64,31 @@ namespace WorkFlowCheck.API.Controllers return retVal; } + [HttpPost("UpdateCheckPoint")] + public async Task> UpdateCheckPoint([FromBody] CheckPointDTO checkPointDTO) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true + }; - [HttpGet("GetCheckPoints/{id}")] - public async Task> GetCheckpointsAsync(int id) + try + { + var result = await _syncService.UpdateCheckPointAsync(checkPointDTO); + retVal.Data = result; + + } + catch (Exception ex) + { + retVal.IsSuccess = false; + Log.Error(ex.Message); + } + return retVal; + } + + + [HttpGet("GetEquipment/{id}")] + public async Task> GetEquipmentAsync(int id) { var retVal = new ApiResponseDTO() { @@ -63,7 +110,6 @@ namespace WorkFlowCheck.API.Controllers return retVal; } - [HttpGet("GetAllEquipments")] public async Task>> GetAllEquipmentsAsync() { @@ -87,7 +133,52 @@ namespace WorkFlowCheck.API.Controllers return retVal; } + [HttpPost("UpdateEquipment")] + public async Task> UpdateEquipment([FromBody] EquipmentDTO EquipmentDTO) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true + }; + try + { + var result = await _syncService.UpdateEquipmentAsync(EquipmentDTO); + retVal.Data = result; + + } + catch (Exception ex) + { + retVal.IsSuccess = false; + Log.Error(ex.Message); + } + return retVal; + } + + + [HttpGet("GetLocation/{id}")] + public async Task> GetLocationAsync(int id) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true, + }; + var checkPointListDTO = await _syncService.GetCheckPointAsync(id); + + if (checkPointListDTO != null) + { + + retVal.IsSuccess = true; + retVal.Data = checkPointListDTO; + } + else + { + retVal.IsSuccess = false; + retVal.Errors.Add("No data!"); + } + + return retVal; + } [HttpGet("GetAllLocations")] public async Task>> GetAllLocationsAsync() { @@ -111,6 +202,28 @@ namespace WorkFlowCheck.API.Controllers return retVal; } + [HttpPost("UpdateLocation")] + public async Task> UpdateLocation([FromBody] LocationDTO LocationDTO) + { + var retVal = new ApiResponseDTO() + { + IsSuccess = true + }; + + try + { + var result = await _syncService.UpdateLocationAsync(LocationDTO); + retVal.Data = result; + + } + catch (Exception ex) + { + retVal.IsSuccess = false; + Log.Error(ex.Message); + } + return retVal; + } + [HttpGet("GetAllCheckListTemplateHeader")] public async Task>> GetAllCheckListTemplateHeaderAsync() @@ -136,26 +249,10 @@ namespace WorkFlowCheck.API.Controllers return retVal; } - [HttpPost("UpdateCheckPoint")] - public async Task> UpdateCheckPoint([FromBody] CheckPointDTO checkPointDTO) - { - var retVal = new ApiResponseDTO() - { - IsSuccess = true - }; + - try - { - var result = await _syncService.UpdateCheckPointAsync(checkPointDTO); - retVal.Data = result; - - } - catch (Exception ex) - { - retVal.IsSuccess = false; - Log.Error(ex.Message); - } - return retVal; - } + + + } } diff --git a/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs b/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs index ef444a1..4e572ff 100644 --- a/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs +++ b/src/WorkFlowCheck.BL/Mappings/MapperProfile.cs @@ -38,9 +38,11 @@ namespace WorkFlowCheck.BL.Mappings CreateMap(); CreateMap(); - + CreateMap(); + CreateMap(); - + CreateMap(); + CreateMap() .ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows)); } diff --git a/src/WorkFlowCheck.BL/Services/CheckListService.cs b/src/WorkFlowCheck.BL/Services/CheckListService.cs index 6c71bc2..c605599 100644 --- a/src/WorkFlowCheck.BL/Services/CheckListService.cs +++ b/src/WorkFlowCheck.BL/Services/CheckListService.cs @@ -160,7 +160,7 @@ namespace WorkFlowCheck.BL.Services var res = await _dbContext.CheckListTemplateHeaders .Where(w => w.Id == Id) .Include(i => i.CheckListTemplateRows) - .ThenInclude(i=> i.CheckPoint) + .ThenInclude(i => i.CheckPoint) .Include(i => i.CheckListTemplateRows) .ThenInclude(i => i.Equipment) .AsNoTracking() @@ -210,7 +210,7 @@ namespace WorkFlowCheck.BL.Services { Description = checkListTemplateHeaderDTO.Description, ShortName = checkListTemplateHeaderDTO.ShortName, - IsDeleted =false, + IsDeleted = false, }; _dbContext.CheckListTemplateHeaders.Add(checkListTemplateHeader); @@ -226,7 +226,7 @@ namespace WorkFlowCheck.BL.Services if (checkListTemplateHeader != null) { checkListTemplateHeader.Description = checkListTemplateHeaderDTO.Description; - checkListTemplateHeader.ShortName = checkListTemplateHeaderDTO.ShortName; + checkListTemplateHeader.ShortName = checkListTemplateHeaderDTO.ShortName; await _dbContext.SaveChangesAsync(); retVal = _mapper.Map(checkListTemplateHeader); @@ -247,8 +247,8 @@ namespace WorkFlowCheck.BL.Services try { var res = await _dbContext.CheckListTemplateRows - .Include(i=> i.Equipment) - .Include(i=> i.CheckPoint) + .Include(i => i.Equipment) + .Include(i => i.CheckPoint) .Where(w => w.Id == id) .AsNoTracking() .FirstOrDefaultAsync(); @@ -266,6 +266,52 @@ namespace WorkFlowCheck.BL.Services return retVal; } - public Task UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO) => throw new NotImplementedException(); + public async Task UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO) + { + var retVal = new CheckListTemplateRowDTO() { }; + try + { + if (checkListTemplateRowDTO.Id == 0) + { + var checkListTemplateRow = new CheckListTemplateRow() + { + CheckListTemplateHeaderId = checkListTemplateRowDTO.CheckListTemplateHeaderId, + CheckPointId = checkListTemplateRowDTO.CheckPointId, + EquipmentId = checkListTemplateRowDTO.EquipmentId, + OperationDescription = checkListTemplateRowDTO.OperationDescription, + AnswerType = checkListTemplateRowDTO.AnswerType, + RowIndex = checkListTemplateRowDTO.RowIndex, + + }; + _dbContext.CheckListTemplateRows.Add(checkListTemplateRow); + await _dbContext.SaveChangesAsync(); + retVal = _mapper.Map(checkListTemplateRow); + } + else + { + var checkListTemplateRow = await _dbContext.CheckListTemplateRows + .Where(w => w.Id == checkListTemplateRowDTO.Id) + .FirstOrDefaultAsync(); + if (checkListTemplateRow != null) + { + checkListTemplateRow.CheckListTemplateHeaderId = checkListTemplateRowDTO.CheckListTemplateHeaderId; + checkListTemplateRow.CheckPointId = checkListTemplateRowDTO.CheckPointId; + checkListTemplateRow.EquipmentId = checkListTemplateRowDTO.EquipmentId; + checkListTemplateRow.OperationDescription = checkListTemplateRowDTO.OperationDescription; + checkListTemplateRow.AnswerType = checkListTemplateRowDTO.AnswerType; + checkListTemplateRow.RowIndex = checkListTemplateRowDTO.RowIndex; + + await _dbContext.SaveChangesAsync(); + retVal = _mapper.Map(checkListTemplateRow); + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } } } diff --git a/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs index 620c83e..f51b516 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs @@ -8,8 +8,17 @@ namespace WorkFlowCheck.BL.Services.Interfaces Task> GetAllCheckPointAsync(); Task GetCheckPointAsync(int id); Task UpdateCheckPointAsync(CheckPointDTO checkPointDTO); + + Task> GetAllLocationAsync(); + Task GetLocationAsync(int id); + Task UpdateLocationAsync(LocationDTO LocationDTO); + + Task> GetAllEquipmentAsync(); + Task GetEquipmentAsync(int id); + Task UpdateEquipmentAsync(EquipmentDTO EquipmentDTO); + Task> GetAllCheckListTemplateAsync(); } diff --git a/src/WorkFlowCheck.BL/Services/SyncService.cs b/src/WorkFlowCheck.BL/Services/SyncService.cs index a0d9ede..3cbe307 100644 --- a/src/WorkFlowCheck.BL/Services/SyncService.cs +++ b/src/WorkFlowCheck.BL/Services/SyncService.cs @@ -101,6 +101,9 @@ namespace WorkFlowCheck.BL.Services return retVal; } + + + public async Task> GetAllLocationAsync() { var retVal = new List(); @@ -120,6 +123,67 @@ namespace WorkFlowCheck.BL.Services return retVal; } + public async Task GetLocationAsync(int id) + { + var retVal = new LocationDTO(); + + try + { + var res = await _dbContext.Locations + .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 UpdateLocationAsync(LocationDTO LocationDTO) + { + var retVal = new LocationDTO(); + + try + { + if (LocationDTO.Id == 0) //Hozzáadás, ha Id == 0 + { + var Location = _mapper.Map(LocationDTO); + _dbContext.Locations.Add(Location); + await _dbContext.SaveChangesAsync(); + + retVal = _mapper.Map(Location); + } + else + { + var res = await _dbContext.Locations.Where(w => w.Id == LocationDTO.Id).FirstOrDefaultAsync(); + if (res != null) + { + res=_mapper.Map(LocationDTO); + + await _dbContext.SaveChangesAsync(); + + retVal = _mapper.Map(res); + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } + + + + + public async Task> GetAllEquipmentAsync() { var retVal = new List(); @@ -139,6 +203,63 @@ namespace WorkFlowCheck.BL.Services return retVal; } + public async Task GetEquipmentAsync(int id) + { + var retVal = new EquipmentDTO(); + + try + { + var res = await _dbContext.Equipments + .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 UpdateEquipmentAsync(EquipmentDTO EquipmentDTO) + { + var retVal = new EquipmentDTO(); + + try + { + if (EquipmentDTO.Id == 0) //Hozzáadás, ha Id == 0 + { + var Equipment = _mapper.Map(EquipmentDTO); + _dbContext.Equipments.Add(Equipment); + await _dbContext.SaveChangesAsync(); + + retVal = _mapper.Map(Equipment); + } + else + { + var res = await _dbContext.Equipments.Where(w => w.Id == EquipmentDTO.Id).FirstOrDefaultAsync(); + if (res != null) + { + res.ShortName = EquipmentDTO.ShortName; + res.EquipmentNumber = EquipmentDTO.EquipmentNumber; + + await _dbContext.SaveChangesAsync(); + + retVal = _mapper.Map(res); + } + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } public async Task> GetAllCheckListTemplateAsync() { var retVal = new List(); diff --git a/src/WorkFlowCheck.Common/DTO/CheckListTemplateRowDTO.cs b/src/WorkFlowCheck.Common/DTO/CheckListTemplateRowDTO.cs index 48acd2b..e1b194d 100644 --- a/src/WorkFlowCheck.Common/DTO/CheckListTemplateRowDTO.cs +++ b/src/WorkFlowCheck.Common/DTO/CheckListTemplateRowDTO.cs @@ -7,13 +7,13 @@ namespace WorkFlowCheck.Common.DTO public int Id { get; set; } public int RowIndex { get; set; } public int CheckListTemplateHeaderId { get; set; } - + public int EquipmentId { get; set; } - public EquipmentDTO EquipmentDTO { get; set; } - + public EquipmentDTO? EquipmentDTO { get; set; } = null!; + public int CheckPointId { get; set; } - public CheckPointDTO CheckPointDTO { get; set; } - + public CheckPointDTO? CheckPointDTO { get; set; } = null!; + public string OperationDescription { get; set; } = null!; /// @@ -29,6 +29,6 @@ namespace WorkFlowCheck.Common.DTO /// public string AnswerType { get; set; } = null!; - + } } diff --git a/src/WorkFlowCheck.Web/Middleware/JwtMiddleware.cs b/src/WorkFlowCheck.Web/Middleware/JwtMiddleware.cs index 3dec41d..29eff5e 100644 --- a/src/WorkFlowCheck.Web/Middleware/JwtMiddleware.cs +++ b/src/WorkFlowCheck.Web/Middleware/JwtMiddleware.cs @@ -25,7 +25,14 @@ namespace WorkFlowCheck.Web.Middleware { context.User = new ClaimsPrincipal(new ClaimsIdentity(claims, "jwt")); } - + else + { + // Ha token van, de invalid, töröljük a cookiet + if (!string.IsNullOrEmpty(token)) + { + context.Response.Cookies.Delete("AuthToken"); + } + } await _next(context); } private bool ValidateToken(string token, out Claim[] claims) diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml index b487a02..6a30f7c 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml @@ -1,4 +1,96 @@ @page @model WorkFlowCheck.Web.Pages.BaseStock.Equipments.EquipmentEditPageModel +@using Microsoft.AspNetCore.Antiforgery +@inject IAntiforgery Antiforgery @{ + ViewData["Title"] = "Berendezés"; + var EquipmentId = Model.EquipmentDTO.Id; + var urlPost = Url.Page("./EquipmentEditPage", "Save"); } +

@ViewData["Title"]

+ + + +
+
+ + +
+ + + +
+
+ + + +
+
+ + +
+
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml.cs index 9b66a43..b5f738d 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentEditPage.cshtml.cs @@ -1,12 +1,49 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Serilog; +using WorkFlowCheck.Common.DTO; +using WorkFlowCheck.Web.Services.Interfaces; namespace WorkFlowCheck.Web.Pages.BaseStock.Equipments { public class EquipmentEditPageModel : PageModel { - public void OnGet() + private readonly ILogger _logger; + private readonly IBaseStockService _baseStockService; + + [BindProperty] + public EquipmentDTO EquipmentDTO { get; set; } + + public EquipmentEditPageModel(ILogger logger, IBaseStockService baseStockService) { + _baseStockService = baseStockService; + _logger = logger; + } + + public async Task OnGet(int id) + { + EquipmentDTO = await _baseStockService.GetEquipment(id); + } + public async Task OnPostSave([FromBody] EquipmentDTO equipmentDTO) + { + try + { + var result = await _baseStockService.UpdateEquipment(equipmentDTO); + 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/Pages/BaseStock/Equipments/EquipmentsPage.cshtml b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml index 42dc065..bf94237 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/Equipments/EquipmentsPage.cshtml @@ -7,13 +7,16 @@
- +
+ @@ -21,6 +24,7 @@ + @@ -38,6 +42,7 @@ columns: [ { data: "id" }, { data: "shortName" }, + { data: "equipmentNumber" }, { data: null, render: function (data, type, row) { return renderActionButtons(row.id); }} @@ -48,9 +53,9 @@ "visible": false }, { - "targets": 2, + "targets": 3, "className": "text-center", - "width": "10" + "width": "10%" } ], @@ -58,6 +63,11 @@ language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',} }); + $('#newEquipmentBtn').on('click', function () + { + window.location.href = `@Url.Page("/BaseStock/Equipments/EquipmentEditPage")?id=0`; + }); + $('#tbEquipmentsPage').on('click', '.edit-btn', function () { const row = table.row($(this).closest('tr')).data(); diff --git a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderEditPage.cshtml index 855f6b1..917d668 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateHeader/CheckListTemplateHeaderEditPage.cshtml @@ -31,7 +31,7 @@

-
@@ -91,11 +91,19 @@ processing:true, language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',} }); + + + $('#newCheckListTemplateRowBtn').on('click', function () { + const parentId = @CheckListTemplateHeaderId; + window.location.href = '@Url.Page("/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage", "New")' + `&parentId=${parentId}`; + }); + + $('#tbCheckListTemplateHeaderPage').on('click', '.edit-btn', function () { const row = table.row($(this).closest('tr')).data(); window.location.href = `@Url.Page("/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage")?id=${row.id}`; - + }); $('#tbCheckListTemplateHeaderPage').on('click', '.delete-btn', function () diff --git a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml index 81bd2cf..d6cc627 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml +++ b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml @@ -1,4 +1,4 @@ -@page +@page @model WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows.CheckListTemplateRowEditPageModel @using Microsoft.AspNetCore.Antiforgery @inject IAntiforgery Antiforgery @@ -70,7 +70,7 @@ 'X-CSRF-TOKEN': csrfToken, 'Content-Type': 'application/json' }, - data: JSON.stringify(formData.CheckPoint), + data: JSON.stringify(formData.CheckListTemplateRow), success: function (response) { showMessageModal({ title: 'Figyelmem!', diff --git a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml.cs index 16ac183..6799762 100644 --- a/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/CheckListTemplate/CheckListTemplateRows/CheckListTemplateRowEditPage.cshtml.cs @@ -1,6 +1,7 @@ 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; @@ -9,6 +10,7 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows public class CheckListTemplateRowEditPageModel : PageModel { private readonly ILogger _logger; + private readonly ICheckListService _checkListService; private readonly IBaseStockService _baseStockService; @@ -27,8 +29,9 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows [BindProperty] public List Equipments { get; set; } - public CheckListTemplateRowEditPageModel(ILogger logger, IBaseStockService baseStockService) + public CheckListTemplateRowEditPageModel(ILogger logger, ICheckListService checkListService, IBaseStockService baseStockService) { + _checkListService = checkListService; _baseStockService = baseStockService; _logger = logger; } @@ -36,7 +39,64 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows public async Task OnGet(int id) { await InitSelectItems(); - CheckListTemplateRow = await _baseStockService.GetCheckListTemplateRow(id); + CheckListTemplateRow = await _checkListService.GetCheckListTemplateRow(id); + } + + public async Task OnGetNew(int parentId) + { + await InitSelectItems(); + + var checkListTemplateHeader = await _checkListService.GetCheckListTemplateHeader(parentId); + + if (checkListTemplateHeader != null) + { + int rowIndex = 1; + int equipmentId = 0; + int checkPointId = 0; + + if (checkListTemplateHeader.CheckListTemplateRowDTO.Count() > 0) + { + var checkListTemplateRowMax = checkListTemplateHeader.CheckListTemplateRowDTO.OrderByDescending(o => o.RowIndex).FirstOrDefault(); + if (checkListTemplateRowMax != null) + { + rowIndex = checkListTemplateRowMax.RowIndex + 1; + checkPointId=checkListTemplateRowMax.CheckPointId; + equipmentId= checkListTemplateRowMax.EquipmentId; + } + } + + CheckListTemplateRow = new CheckListTemplateRowDTO() + { + Id = 0, + CheckListTemplateHeaderId = parentId, + RowIndex = rowIndex, + EquipmentId = equipmentId, + CheckPointId = checkPointId, + AnswerType = "I-N" + }; + } + + } + public async Task OnPostSave([FromBody] CheckListTemplateRowDTO checkListTemplateRowDTO) + { + try + { + var result = await _checkListService.UpdateCheckListTemplateRow(checkListTemplateRowDTO); + 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 }); } private async Task InitSelectItems() { @@ -53,5 +113,6 @@ namespace WorkFlowCheck.Web.Pages.CheckListTemplate.CheckListTemplateRows this.Equipments.Add(new SelectListItem() { Value = equipment.Id.ToString(), Text = equipment.ShortName }); } } + } } diff --git a/src/WorkFlowCheck.Web/Program.cs b/src/WorkFlowCheck.Web/Program.cs index 5deba49..6178d24 100644 --- a/src/WorkFlowCheck.Web/Program.cs +++ b/src/WorkFlowCheck.Web/Program.cs @@ -75,8 +75,16 @@ app.UseAuthorization(); app.Use(async (context, next) => { - if (string.IsNullOrEmpty(context.User?.Identity?.Name) && - context.Request.Path == "/") + //if (string.IsNullOrEmpty(context.User?.Identity?.Name) && + // context.Request.Path == "/") + //{ + // context.Response.Redirect("/Account/Login"); + // return; + //} + var isAuthenticated = context.User?.Identity?.IsAuthenticated == true; + var path = context.Request.Path.Value?.ToLower(); + + if (!isAuthenticated && !path.StartsWith("/account/login")) { context.Response.Redirect("/Account/Login"); return; diff --git a/src/WorkFlowCheck.Web/Services/BaseStockService.cs b/src/WorkFlowCheck.Web/Services/BaseStockService.cs index c052e72..8761002 100644 --- a/src/WorkFlowCheck.Web/Services/BaseStockService.cs +++ b/src/WorkFlowCheck.Web/Services/BaseStockService.cs @@ -80,7 +80,7 @@ namespace WorkFlowCheck.Web.Services public async Task GetCheckPoint(int id) { - string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetCheckPoints/{id}"; + string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetCheckPoint/{id}"; var retVal = new CheckPointDTO(); try { @@ -142,28 +142,7 @@ namespace WorkFlowCheck.Web.Services return retVal; } - public async Task GetCheckListTemplateRow(int id) - { - string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListTemplateRow/{id}"; - var retVal = new CheckListTemplateRowDTO(); - 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> UpdateCheckPoint(CheckPointDTO checkPointDTO) { try diff --git a/src/WorkFlowCheck.Web/Services/CheckListService.cs b/src/WorkFlowCheck.Web/Services/CheckListService.cs index 30e2c6b..aa356f3 100644 --- a/src/WorkFlowCheck.Web/Services/CheckListService.cs +++ b/src/WorkFlowCheck.Web/Services/CheckListService.cs @@ -1,4 +1,5 @@ -using Serilog; +using Newtonsoft.Json; +using Serilog; using System.Net.Http; using WorkFlowCheck.Common.DTO; using WorkFlowCheck.Web.Services.Interfaces; @@ -99,5 +100,56 @@ namespace WorkFlowCheck.Web.Services return retVal; } public async Task> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO) => throw new NotImplementedException(); + + public async Task GetCheckListTemplateRow(int id) + { + string endpoint = $"{_httpClient.BaseAddress}api/CheckList/GetCheckListTemplateRow/{id}"; + var retVal = new CheckListTemplateRowDTO(); + 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> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO) + { + try + { + string endpoint = $"{_httpClient.BaseAddress}api/CheckList/UpdateCheckListTemplateRow"; + + using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkListTemplateRowDTO)) + { + 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/IBaseStockService.cs b/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs index 1a815c1..317e2df 100644 --- a/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs +++ b/src/WorkFlowCheck.Web/Services/Interfaces/IBaseStockService.cs @@ -4,11 +4,18 @@ namespace WorkFlowCheck.Web.Services.Interfaces { public interface IBaseStockService { - Task> GetAllCheckPoints(); - Task> GetAllEquipments(); - Task> GetAllLocations(); + Task GetCheckPoint(int id); - Task GetCheckListTemplateRow(int id); - Task> UpdateCheckPoint(CheckPointDTO checkPoint); + Task> GetAllCheckPoints(); + Task> UpdateCheckPoint(CheckPointDTO checkPointDTO); + + + Task GetEquipment(int id); + Task> GetAllEquipments(); + Task> UpdateEquipment(EquipmentDTO equipmentDTO); + + Task GetLocation(int id); + Task> GetAllLocations(); + Task> UpdateLocation(LocationDTO LocationDTO); } } diff --git a/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs index 2504e75..5522b9e 100644 --- a/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.Web/Services/Interfaces/ICheckListService.cs @@ -12,5 +12,8 @@ namespace WorkFlowCheck.Web.Services.Interfaces Task> GetAllCheckListTemplateHeaderAsync(); Task> UpdateCheckListTemplateHeader(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO); + Task GetCheckListTemplateRow(int id); + Task> UpdateCheckListTemplateRow(CheckListTemplateRowDTO checkListTemplateRowDTO); + } }
ID Short NameEquipment Number Action
ID Short NameEquipment Number Action