demo20230512/Controllers/Api/RiskAssmt/ItemDeliveryController.cs

103 lines
3.5 KiB
C#
Raw 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;
namespace Weee.Controllers.Api.RiskAssmt
{
public class ItemDeliveryController : ApiControllerBase
{
private readonly ItemDeliveryDataService service;
public ItemDeliveryController(ItemDeliveryDataService d) : base(d)
{
service = d;
}
[Route("api/ItemDelivery/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/ItemDelivery/Save/{LCAID}/{id}")]
[HttpPost]
public object Save(int LCAID, int id, LCARiskAssmtSurveyForm_ItemDelivery 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_ItemDelivery ToBeSave)
{
if (string.IsNullOrEmpty(ToBeSave.MaterialNo))
{
//ModelState.AddModelError(nameof(ToBeSave.MaterialNo), "请输入料号");
throw new Exception("请输入料号");
}
if (string.IsNullOrEmpty(ToBeSave.ModelName))
{
//ModelState.AddModelError(nameof(ToBeSave.ModelName), "请输入机种名");
throw new Exception("请输入机种名");
}
if (string.IsNullOrEmpty(ToBeSave.Fab))
{
//ModelState.AddModelError(nameof(ToBeSave.Fab), "请输入工厂");
throw new Exception("请输入工厂");
}
if (ToBeSave.DeliveryAmount <= 0)
{
//ModelState.AddModelError(nameof(ToBeSave.DeliveryAmount), "出货数量必须大于零");
throw new Exception("出货数量必须大于零");
}
if (ToBeSave.TotalWeightKg <= 0)
{
//ModelState.AddModelError(nameof(ToBeSave.TotalWeightKg), "总重量必须大于零");
throw new Exception("总重量必须大于零");
}
if (string.IsNullOrEmpty(ToBeSave.DeliveryAddr))
{
//ModelState.AddModelError(nameof(ToBeSave.DeliveryAddr), "请输入出货地址");
throw new Exception("请输入出货地址");
}
if (ToBeSave.TransportLand <= 0)
{
//ModelState.AddModelError(nameof(ToBeSave.TransportLand), "路程一(陸運)必须大于零");
throw new Exception("路程一(陸運)必须大于零");
}
}
[Route("api/ItemDelivery/Delete/{ID}")]
[HttpDelete]
public IHttpActionResult Delete(int ID)
{
service.Delete(ID);
return Ok();
}
}
}