demo20230512/Controllers/Api/RiskAssmt/WasteMaterialController.cs

69 lines
1.9 KiB
C#
Raw Permalink Normal View History

2023-05-12 10:20:28 +08:00
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;
using Weee.ViewModels.DataTransferObject;
namespace Weee.Controllers.Api.RiskAssmt
{
public class WasteMaterialController : ApiControllerBase
{
private readonly WasteMaterialDataService service;
public WasteMaterialController(WasteMaterialDataService d) : base(d)
{
service = d;
}
[Route("api/WasteMaterial/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
{
Materials = query.ToList(),
LCA = service.GetLCA(LCAID)
};
}
[Route("api/WasteMaterial/Save/{LCAID}/{id}")]
[HttpPost]
public object Save(int LCAID, int id, LCARiskAssmtSurveyForm_WasteMaterial ToBeSave)
{
if (!ModelState.IsValid) { return BadRequest(); }
if (id != ToBeSave.ID || LCAID != ToBeSave.LCAID) { return BadRequest(); }
service.Save(ToBeSave, out decimal totalQuantity);
return new
{
Model = ToBeSave,
TotalQuantity = totalQuantity
};
}
[Route("api/WasteMaterial/UpdateLCA/{LCAID}")]
[HttpPost]
public object UpdateLCA(int LCAID, LCAWasteMaterialDTO ToBeSave)
{
var lca = service.UpdateLCA(LCAID, ToBeSave);
return lca;
}
[Route("api/WasteMaterial/Delete/{ID}")]
[HttpDelete]
public IHttpActionResult Delete(int ID)
{
service.Delete(ID);
return Ok();
}
}
}