FIC_Solar/SolarPower/Controllers/StationOverviewController.cs
2021-07-06 20:19:23 +08:00

58 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SolarPower.Models;
using SolarPower.Models.PowerStation;
using SolarPower.Repository.Interface;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace SolarPower.Controllers
{
public class StationOverviewController : MyBaseController<StationOverviewController>
{
private readonly IOverviewRepository overviewRepository;
private string stationImageFilePath = "/upload/power_station/";
public StationOverviewController(
IOverviewRepository overviewRepository) : base()
{
this.overviewRepository = overviewRepository;
}
public IActionResult Index()
{
return View();
}
/// <summary>
/// 取得該使用者可看的所有電站分佈縣市以及各縣市電站數量
/// </summary>
/// <returns></returns>
public async Task<ApiResult<List<PowerStation>>> GetSolarByCity(UseStatusCityGetPowerStation post)
{
ApiResult<List<PowerStation>> apiResult = new ApiResult<List<PowerStation>>();
List<PowerStation> solaramount = new List<PowerStation>();
try
{
apiResult.Code = "0000";
solaramount = await overviewRepository.GetSolarByCity(myUser, post);
foreach (var solar in solaramount)
{
solar.MainDisplay = Path.Combine(stationImageFilePath, solar.Id.ToString()) + "/" + solar.MainDisplay;
}
apiResult.Data = solaramount;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = exception.ToString();
}
return apiResult;
}
}
}