67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Http;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.Logging;
|
||
|
||
using SolarPower.Models;
|
||
using SolarPower.Models.User;
|
||
using SolarPower.Repository.Interface;
|
||
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace SolarPower.Controllers
|
||
{
|
||
public class PowerStationController : MyBaseController<PowerStationController>
|
||
{
|
||
private readonly IUserRepository userRepository;
|
||
|
||
public PowerStationController(IUserRepository userRepository) : base()
|
||
{
|
||
this.userRepository = userRepository;
|
||
}
|
||
public IActionResult Index()
|
||
{
|
||
return View();
|
||
}
|
||
|
||
public IActionResult Add()
|
||
{
|
||
return View("~/Views/PowerStation/PowerStationAdd.cshtml");
|
||
}
|
||
|
||
public IActionResult Edit()
|
||
{
|
||
return View("~/Views/PowerStation/PowerStationEdit.cshtml");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取得下拉式公司選單,須為Deleted: 0
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<ApiResult<List<UserSelectItemList>>> GetUserSelectOptionListAsync()
|
||
{
|
||
ApiResult<List<UserSelectItemList>> apiResult = new ApiResult<List<UserSelectItemList>>();
|
||
try
|
||
{
|
||
EDFunction edFunction = new EDFunction();
|
||
var companyId= Convert.ToInt32(edFunction.AESDecrypt(HttpContext.Session.GetString("CompanyId"))); //將公司id透過AES解密
|
||
var userSelectItemLists = await userRepository.GetUserSelectOptionListAsync(companyId);
|
||
|
||
apiResult.Code = "0000";
|
||
apiResult.Data = userSelectItemLists;
|
||
}
|
||
catch (Exception exception)
|
||
{
|
||
apiResult.Code = "9999";
|
||
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
|
||
}
|
||
|
||
apiResult.Msg = errorCode.GetString(apiResult.Code);
|
||
return apiResult;
|
||
}
|
||
}
|
||
}
|