From 1e0fbdfb3bb5846a2bc10e2b4021f6e7885d3840 Mon Sep 17 00:00:00 2001 From: dev02 Date: Mon, 12 Dec 2022 16:11:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B7=A8=E8=BC=AF=E5=9C=96=E8=B3=87crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiControllers/GraphManageController.cs | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/FrontendWebApi/ApiControllers/GraphManageController.cs b/FrontendWebApi/ApiControllers/GraphManageController.cs index ac7f6de..9887493 100644 --- a/FrontendWebApi/ApiControllers/GraphManageController.cs +++ b/FrontendWebApi/ApiControllers/GraphManageController.cs @@ -93,6 +93,10 @@ namespace FrontendWebApi.ApiControllers } + /// + /// 圖資類別列表 + /// + /// [HttpPost] public async Task>> VarList() { @@ -120,6 +124,119 @@ namespace FrontendWebApi.ApiControllers return apiResult; } + /// + /// 新增圖資類別 + /// + /// + /// + [HttpPost] + public async Task> SaveVar([FromBody] GraphVar gv) + { + ApiResult apiResult = new ApiResult(); + + try + { + Dictionary variable = new Dictionary(); + var system_value = backendRepository.GetOneAsync("select system_value from variable where system_type = @system_type and deleted = 0 order by system_value desc limit 1", new { @system_type = gv.system_type }).Result; + variable.Add("@deleted", 0); + variable.Add("@system_type", gv.system_type); + variable.Add("@system_key", gv.system_key); + variable.Add("@system_parent_id", gv.system_parent_id); + variable.Add("@system_remark", "圖資管理-" + gv.system_key); + variable.Add("@priority", Int32.Parse(system_value) + 1); + variable.Add("@system_value", Int32.Parse(system_value) + 1); + variable.Add("@created_by", myUser.userinfo_guid); + variable.Add("@created_at", DateTime.Now); + + await backendRepository.AddOneByCustomTable(variable, "variable"); + apiResult.Code = "0000"; + apiResult.Data = "新增成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + string json = System.Text.Json.JsonSerializer.Serialize(gv); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + /// + /// 編輯圖資類別 + /// + /// + /// + [HttpPost] + public async Task> EditVar([FromBody] GraphVar gv) + { + ApiResult apiResult = new ApiResult(); + var gm = await backendRepository.GetOneAsync("select * from variable where id = @id and deleted = 0", new { @id = gv.id }); + + if (gm != null) + { + apiResult.Code = "0002"; + apiResult.Data = "無法找到圖資"; + return apiResult; + } + + try + { + Dictionary variable = new Dictionary(); + var system_value = backendRepository.GetOneAsync("select system_value from variable where system_type = @system_type and deleted = 0 order by system_value desc limit 1", new { @system_type = gv.system_type }).Result; + + variable.Add("@system_key", gv.system_key); + variable.Add("@updated_by", myUser.userinfo_guid); + variable.Add("@updated_at", DateTime.Now); + + await backendRepository.UpdateOneByCustomTable(variable, "variable", "id = " + gv.id); + apiResult.Code = "0000"; + apiResult.Data = "編輯成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + string json = System.Text.Json.JsonSerializer.Serialize(gv); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + + /// + /// 刪除圖資類別 + /// + /// + /// + [HttpPost] + public async Task> DelOneGraMan([FromBody] GraphVar gv) + { + ApiResult apiResult = new ApiResult(); + + try + { + var sqlString = @$"UPDATE variable SET deleted = 1, updated_at = @time, updated_by = @user WHERE id = @id"; + + var param = new { @id = gv.id, @time = DateTime.Now, @user = myUser.userinfo_guid }; + + await backendRepository.ExecuteSql(sqlString, param); + apiResult.Code = "0000"; + apiResult.Data = "刪除成功"; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + return apiResult; + } + [HttpPost] public async Task>> GraManList([FromBody] GraphInfo gi) {