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 TransportController : ApiControllerBase { private readonly WeeeParameterDataService parameterservice; private readonly WeeeSheetDataService service; public TransportController(WeeeSheetDataService d, WeeeParameterDataService s) : base(d) { service = d; parameterservice = s; } [Route("api/Transport/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(lcaId); if (search != "") { query = query.Where(x => x.JourneyNO.Contains(search) || x.StartLocation.Contains(search) || x.EndLocation.Contains(search)); } return new { Transports = query.ToList(), Options = parameterservice.GetNonYearlyParameterOptions(Categories.Transport), SheetHeader = service.GetSheetHeader(lcaId, Categories.Transport) }; } [Route("api/Transport/SaveSheetHeader")] [HttpPost] public HttpResponseMessage SaveHeader(SheetHeader header) { return this.SaveSheetHeader(service, Weee.Models.Paramemter.Categories.Transport, header); } [Route("api/Transport/SaveAll")] [HttpPost] [ApiEditableAttribute("toBeSave", true)] public object SaveAll(IEnumerable toBeSave) { if (!ModelState.IsValid) throw new Exception("error"); var result = service.SaveSheet(toBeSave); return new { result = result }; } [Route("api/Transport/Save/{lcaId}/{id}")] [HttpPost] [ApiEditableAttribute("toBeSave", false)] public Object Save(int lcaId, int id, ProductLCAFabSurveyForm_Transports toBeSave) { ModelState.Remove("id"); if (toBeSave.TransportDate.Year < 2000) ModelState.AddModelError("TransportDate", "出貨日期錯誤"); if (!ModelState.IsValid) return BadRequest(); if (id != toBeSave.ID || lcaId != toBeSave.LCAID) return BadRequest(); toBeSave.ParameterUnit += ""; service.SaveSheetItem(toBeSave); return toBeSave; } [Route("api/Transport/DeleteAll/{lcaId}")] [HttpDelete] public IHttpActionResult DeleteAll(int lcaId) { service.DeleteSheet(lcaId); return Ok(); } [Route("api/Transport/Delete/{id}")] [HttpDelete] public IHttpActionResult Delete(int id) { service.DeleteSheetItem(id); return Ok(); } } }