using FrontendWebApi.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Repository.BackendRepository.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace FrontendWebApi.Controllers { public class EmergencyRecordController : MyBaseController<EmergencyRecordController> { private readonly IBackendRepository backendRepository; public EmergencyRecordController(IBackendRepository backendRepository) { this.backendRepository = backendRepository; } public IActionResult Index() { return View(); } [HttpPost] public async Task<ApiResult<List<KeyValue>>> DisasterList() { ApiResult<List<KeyValue>> apiResult = new ApiResult<List<KeyValue>>(); List<KeyValue> Variable = new List<KeyValue>(); try { var sqlString = @$"select system_value as Value, system_key as Name from variable a where a.system_type = 'disaster' and a.deleted = 0"; Variable = await backendRepository.GetAllAsync<KeyValue>(sqlString); apiResult.Code = "0000"; apiResult.Data = Variable; } catch (Exception exception) { apiResult.Code = "9999"; apiResult.Msg = "系統內部錯誤,請聯絡管理者。"; Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } return apiResult; } } }