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 IntlTravelController : ApiControllerBase { private readonly IntlTravelDataService service; public IntlTravelController(IntlTravelDataService d) : base(d) { service = d; } [Route("api/IntlTravel/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 { Purchases = query.ToList(), //OptionsOne = gwpOptions, //OptionsTwo = parameterservice.GetNonYearlyParameterOptions(Categories.Refrigerant), //SheetHeader = service.GetSheetHeader(LCAID, Categories.Refrigerant) }; } [Route("api/IntlTravel/Save/{LCAID}/{id}")] [HttpPost] public object Save(int LCAID, int id, LCARiskAssmtSurveyForm_IntlTravel ToBeSave) { ModelValidation(ToBeSave); if (!ModelState.IsValid) { return BadRequest(); } if (id != ToBeSave.ID || LCAID != ToBeSave.LCAID) { return BadRequest(); } service.Save(ToBeSave); return ToBeSave; } private void ModelValidation(LCARiskAssmtSurveyForm_IntlTravel ToBeSave) { if (string.IsNullOrEmpty(ToBeSave.Traveller)) { throw new Exception("请输入姓名"); } //if (ToBeSave.TravelDate) //{ // throw new Exception("请输入出差日期"); //} if (string.IsNullOrEmpty(ToBeSave.AirportFrom)) { throw new Exception("请输入起點機場"); } if (string.IsNullOrEmpty(ToBeSave.AirportTo)) { throw new Exception("请输入迄點機場"); } if (string.IsNullOrEmpty(ToBeSave.AirportClass)) { throw new Exception("请输入艙等"); } } [Route("api/IntlTravel/Delete/{ID}")] [HttpDelete] public IHttpActionResult Delete(int ID) { service.Delete(ID); return Ok(); } } }