FIC_Solar/SolarPower/Controllers/PowerGenerationController.cs
2021-08-19 10:50:46 +08:00

53 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SolarPower.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SolarPower.Models;
using SolarPower.Models.PowerStation;
using Microsoft.Extensions.Logging;
namespace SolarPower.Controllers
{
public class PowerGenerationController : MyBaseController<PowerGenerationController>
{
private readonly IElectricitySoldRecordRepository electricitySoldRecordRepository;
private readonly IPowerStationRepository powerStationRepository;
public PowerGenerationController(IElectricitySoldRecordRepository electricitySoldRecordRepository, IPowerStationRepository powerStationRepository) : base()
{
this.electricitySoldRecordRepository = electricitySoldRecordRepository;
this.powerStationRepository = powerStationRepository;
}
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<ApiResult<List<Generation>>> GetGenerationList (SearchGeneration post)
{
ApiResult<List<Generation>> apiResult = new ApiResult<List<Generation>>();
try
{
var GenerationList = await electricitySoldRecordRepository.GetGenerationList(post);
apiResult.Data = GenerationList;
apiResult.Code = "0000";
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = exception.ToString();
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "info=" + System.Text.Json.JsonSerializer.Serialize(post));
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
}
}