using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using SolarPower.Models; using SolarPower.Repository.Interface; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace SolarPower.Controllers { public class NoticeScheduleController : MyBaseController { private readonly INoticeScheduleRepository noticeScheduleRepository; public NoticeScheduleController(INoticeScheduleRepository noticeScheduleRepository) : base() { this.noticeScheduleRepository = noticeScheduleRepository; } public IActionResult Index() { return View(); } [HttpPost] public async Task NoticeTable(NoticeTableSearch info) { List NoticeScheduleTable = new List(); ApiResult> apiResult = new ApiResult>(); try { NoticeScheduleTable = await noticeScheduleRepository.GetNoticeTable(info); foreach(NoticeScheduleTable a in NoticeScheduleTable) { a.EmailTypeName = a.EmailType switch { 0 => "日報表", 1 => "月報表", 2 => "綜合報表", 3 => "運維", _ => "" }; a.IsDeliveryName = a.IsDelivery switch { 1 => "成功", 2 => "失敗", _ => "" }; } apiResult.Code = "0000"; apiResult.Data = NoticeScheduleTable; } catch (Exception exception) { apiResult.Code = "9999"; apiResult.Msg = exception.ToString(); Logger.LogError("【" + controllerName + "/" + actionName + "】" + "info=" + System.Text.Json.JsonSerializer.Serialize(info)); Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); } var result = Json(new { data = apiResult }); return result; } } }