diff --git a/src/WorkFlowCheck.API/Controllers/SyncController.cs b/src/WorkFlowCheck.API/Controllers/SyncController.cs index 8985703..8bdedbb 100644 --- a/src/WorkFlowCheck.API/Controllers/SyncController.cs +++ b/src/WorkFlowCheck.API/Controllers/SyncController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Serilog; using WorkFlowCheck.BL.Services; using WorkFlowCheck.BL.Services.Interfaces; using WorkFlowCheck.Common.DTO; @@ -14,7 +15,7 @@ namespace WorkFlowCheck.API.Controllers { _syncService = syncService; } - + [HttpGet("GetAllCheckPoints")] public async Task>> GetAllCheckpointsAsync() { @@ -26,9 +27,9 @@ namespace WorkFlowCheck.API.Controllers if (checkPointListDTO != null) { - - retVal.IsSuccess = true; - retVal.Data = checkPointListDTO; + + retVal.IsSuccess = true; + retVal.Data = checkPointListDTO; } else { @@ -38,7 +39,7 @@ namespace WorkFlowCheck.API.Controllers return retVal; } - + [HttpGet("GetCheckPoints/{id}")] public async Task> GetAllCheckpointsAsync(int id) { @@ -134,5 +135,27 @@ namespace WorkFlowCheck.API.Controllers return retVal; } + + [HttpPost("authenticate")] + 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/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs index 50ab50e..620c83e 100644 --- a/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs +++ b/src/WorkFlowCheck.BL/Services/Interfaces/ISyncService.cs @@ -7,9 +7,10 @@ namespace WorkFlowCheck.BL.Services.Interfaces { Task> GetAllCheckPointAsync(); Task GetCheckPointAsync(int id); + Task UpdateCheckPointAsync(CheckPointDTO checkPointDTO); Task> GetAllLocationAsync(); Task> GetAllEquipmentAsync(); - + Task> GetAllCheckListTemplateAsync(); } } diff --git a/src/WorkFlowCheck.BL/Services/SyncService.cs b/src/WorkFlowCheck.BL/Services/SyncService.cs index 57b4d55..3a21223 100644 --- a/src/WorkFlowCheck.BL/Services/SyncService.cs +++ b/src/WorkFlowCheck.BL/Services/SyncService.cs @@ -66,6 +66,30 @@ namespace WorkFlowCheck.BL.Services return retVal; } + public async Task UpdateCheckPointAsync(CheckPointDTO checkPointDTO) + { + var retVal = new CheckPointDTO(); + + try + { + 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(res); + } + } + catch (Exception ex) + { + Log.Error(ex.Message); + } + + return retVal; + } public async Task> GetAllLocationAsync() { var retVal = new List(); diff --git a/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs b/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs index 1a80347..a81a42c 100644 --- a/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs +++ b/src/WorkFlowCheck.Web/Pages/BaseStock/CheckPoints/CheckPointEditPage.cshtml.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Serilog; using WorkFlowCheck.Common.DTO; using WorkFlowCheck.Web.Services.Interfaces; @@ -31,10 +32,21 @@ namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints CheckPoint = await _baseStockService.GetCheckPoint(id); return new JsonResult(new { data = CheckPoint.CheckListTemplateRowDTO }); } - - public async Task OnPostSave([FromBody] CheckPointDTO checkPointDTO) + + public async Task OnPostSave([FromBody] CheckPointDTO checkPointDTO) { - int i = 0; + + 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 }); } } }