編輯圖資crud

This commit is contained in:
dev02 2022-12-12 16:11:04 +08:00
parent 2107ec9a09
commit 1e0fbdfb3b

View File

@ -93,6 +93,10 @@ namespace FrontendWebApi.ApiControllers
} }
/// <summary>
/// 圖資類別列表
/// </summary>
/// <returns></returns>
[HttpPost] [HttpPost]
public async Task<ApiResult<List<Variable>>> VarList() public async Task<ApiResult<List<Variable>>> VarList()
{ {
@ -120,6 +124,119 @@ namespace FrontendWebApi.ApiControllers
return apiResult; return apiResult;
} }
/// <summary>
/// 新增圖資類別
/// </summary>
/// <param name="gv"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> SaveVar([FromBody] GraphVar gv)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
Dictionary<string, object> variable = new Dictionary<string, object>();
var system_value = backendRepository.GetOneAsync<string>("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;
}
/// <summary>
/// 編輯圖資類別
/// </summary>
/// <param name="gv"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> EditVar([FromBody] GraphVar gv)
{
ApiResult<string> apiResult = new ApiResult<string>();
var gm = await backendRepository.GetOneAsync<GraphInsInfo>("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<string, object> variable = new Dictionary<string, object>();
var system_value = backendRepository.GetOneAsync<string>("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;
}
/// <summary>
/// 刪除圖資類別
/// </summary>
/// <param name="gv"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<string>> DelOneGraMan([FromBody] GraphVar gv)
{
ApiResult<string> apiResult = new ApiResult<string>();
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] [HttpPost]
public async Task<ApiResult<List<GraphList>>> GraManList([FromBody] GraphInfo gi) public async Task<ApiResult<List<GraphList>>> GraManList([FromBody] GraphInfo gi)
{ {