103 lines
3.5 KiB
C#
103 lines
3.5 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.Models.Paramemter;
|
|
using Weee.Service;
|
|
using PagedList;
|
|
using Weee.Filter;
|
|
|
|
namespace Weee.Controllers
|
|
{
|
|
public class WasteController : ApiControllerBase
|
|
{
|
|
private readonly WeeeParameterDataService parameterservice;
|
|
private readonly WeeeSheetDataService service;
|
|
public WasteController(WeeeSheetDataService d, WeeeParameterDataService s) : base(d)
|
|
{
|
|
service = d;
|
|
parameterservice = s;
|
|
}
|
|
|
|
[Route("api/Waste/GetByLcaId/{LCAID}/{page:min(1):int=1}/{search?}/{pagesize:min(4):int=15}")]
|
|
//[Filter.ApiMultilanguage]disable obsolete warning, not sure OK or not
|
|
public object GetByLcaId(int LCAID, int page = 1, string search = "", int pagesize = 15)
|
|
{
|
|
var query = service.GetSheet<ProductLCAFabSurveyForm_Waste>(LCAID);
|
|
if (search != "")
|
|
{
|
|
query = query.Where(x => x.Description.Contains(search) ||
|
|
x.DQIDescription.Contains(search));
|
|
}
|
|
|
|
return new
|
|
{
|
|
Wastes = query.ToList(),
|
|
OptionsOne = parameterservice.GetNonYearlyParameterOptions(Categories.WasteWater),
|
|
OptionsTwo = parameterservice.GetNonYearlyParameterOptions(Categories.Waste),
|
|
SheetHeader = service.GetSheetHeader(LCAID, Categories.WasteWater)
|
|
};
|
|
}
|
|
|
|
[Route("api/WasteWater/SaveSheetHeader")]
|
|
[Route("api/Waste/SaveSheetHeader")]
|
|
[HttpPost]
|
|
public HttpResponseMessage SaveHeader(SheetHeader header)
|
|
{
|
|
return this.SaveSheetHeader(service, Weee.Models.Paramemter.Categories.WasteWater, header);
|
|
}
|
|
|
|
[Route("api/Waste/SaveAll")]
|
|
[HttpPost]
|
|
[ApiEditableAttribute("toBeSave", true)]
|
|
public object SaveAll(IEnumerable<ProductLCAFabSurveyForm_Waste> toBeSave)
|
|
{
|
|
foreach (var rec in toBeSave)
|
|
rec.KgCO2e = rec.ParameterValue * rec.Scalar;
|
|
if (!ModelState.IsValid)
|
|
{
|
|
throw new Exception("error");
|
|
}
|
|
var result = service.SaveSheet(toBeSave);
|
|
return new { result = result };
|
|
}
|
|
|
|
[Route("api/Waste/Save/{LCAID}/{id}")]
|
|
[HttpPost]
|
|
[ApiEditableAttribute("toBeSave", false)]
|
|
public object Save(int LCAID, int id, ProductLCAFabSurveyForm_Waste toBeSave)
|
|
{
|
|
//toBeSave.KgCO2e = toBeSave.Scalar * toBeSave.ParameterValue;
|
|
//ModelState.Remove("KgCO2e");
|
|
if (!ModelState.IsValid)
|
|
return BadRequest();
|
|
if (id != toBeSave.ID || LCAID != toBeSave.LCAID)
|
|
return BadRequest();
|
|
if (toBeSave.Unit == null)
|
|
toBeSave.Unit = "";
|
|
toBeSave.ParameterID = null;
|
|
service.SaveSheetItem(toBeSave);
|
|
|
|
return toBeSave;
|
|
}
|
|
|
|
[Route("api/Waste/DeleteAll/{LCAID}")]
|
|
[HttpDelete]
|
|
public IHttpActionResult DeleteAll(int LCAID)
|
|
{
|
|
service.DeleteSheet<ProductLCAFabSurveyForm_Waste>(LCAID);
|
|
return Ok();
|
|
}
|
|
|
|
[Route("api/Waste/Delete/{ID}")]
|
|
[HttpDelete]
|
|
public IHttpActionResult Delete(int ID)
|
|
{
|
|
service.DeleteSheetItem<ProductLCAFabSurveyForm_Waste>(ID);
|
|
return Ok();
|
|
}
|
|
}
|
|
} |