demo20230512/Controllers/Api/RiskAssmt/PowerConsumptionController.cs
2023-05-12 10:20:28 +08:00

56 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Weee.Models;
using Weee.Service;
namespace Weee.Controllers.Api.RiskAssmt
{
public class PowerConsumptionController : ApiControllerBase
{
private readonly PowerConsumptionDataService service;
public PowerConsumptionController(PowerConsumptionDataService d) : base(d)
{
service = d;
}
[Route("api/PowerConsumption/GetByLcaId/{LCAID}")]
//[Filter.ApiMultilanguage]disable obsolete warning, not sure OK or not
public object GetByLcaId(int LCAID, int page = 1, string search = "", int pagesize = 15)
{
//var type = service.GetLCAType(LCAID);
var query = service.GetList(LCAID);
return new
{
Consumptions = query.ToList(),
//OptionsOne = gwpOptions,
//OptionsTwo = parameterservice.GetNonYearlyParameterOptions(Categories.Refrigerant),
//SheetHeader = service.GetSheetHeader(LCAID, Categories.Refrigerant)
};
}
[Route("api/PowerConsumption/Save/{LCAID}/{id}")]
[HttpPost]
public object Save(int LCAID, int id, LCARiskAssmtSurveyForm_PowerConsumption ToBeSave)
{
if (!ModelState.IsValid) { return BadRequest(); }
if (id != ToBeSave.ID || LCAID != ToBeSave.LCAID) { return BadRequest(); }
service.Save(ToBeSave);
return ToBeSave;
}
[Route("api/PowerConsumption/Delete/{ID}")]
[HttpDelete]
public IHttpActionResult Delete(int ID)
{
service.Delete(ID);
return Ok();
}
}
}