using Microsoft.AspNetCore.Builder;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_IPackInfoRepository;
|
using WIDESEAWCS_IPackInfoService;
|
using WIDESEAWCS_Model.Models;
|
|
namespace WIDESEAWCS_PackInfoService
|
{
|
public class PackTypeService : ServiceBase<Dt_PackType, IPackTypeRepository>, IPackTypeService
|
{
|
|
public PackTypeService(IPackTypeRepository BaseDal) : base(BaseDal)
|
{
|
}
|
|
public override WebResponseContent AddData(SaveModel saveModel)
|
{
|
//先把字典转成JSON,在序列化为实体类
|
string json = JsonConvert.SerializeObject(saveModel.MainData);
|
Dt_PackType _PackType = JsonConvert.DeserializeObject<Dt_PackType>(json);
|
|
if ( _PackType.PackHeight <= 0 || _PackType.PackWidth <= 0 || _PackType.PackHeight <= 0 )
|
{
|
return WebResponseContent.Instance.Error($"添加失败,该箱型长、宽、高必须大于0!");
|
|
}
|
|
//判断是否存在该箱型
|
Dt_PackType temp = BaseDal.QueryFirst(x => x.PackLength == _PackType.PackLength && x.PackWidth == _PackType.PackWidth && x.PackHeight == _PackType.PackHeight);
|
if( !temp.IsNotEmptyOrNull())
|
{
|
saveModel.MainData["Remark"] = _PackType.PackLength + "*" + _PackType.PackWidth + "* " + _PackType.PackHeight;
|
return base.AddData(saveModel);
|
|
}
|
return WebResponseContent.Instance.Error($"添加失败,库存已存在该箱型!");
|
|
}
|
|
public override WebResponseContent UpdateData(SaveModel saveModel)
|
{
|
//先把字典转成JSON,在序列化为实体类
|
string json = JsonConvert.SerializeObject(saveModel.MainData);
|
Dt_PackType _PackType = JsonConvert.DeserializeObject<Dt_PackType>(json);
|
|
if ( _PackType.PackHeight <= 0 || _PackType.PackWidth <= 0 || _PackType.PackHeight <= 0 )
|
{
|
return WebResponseContent.Instance.Error($"修改失败,该箱型长、宽、高必须大于0!");
|
|
}
|
|
//判断是否存在该箱型
|
Dt_PackType temp = BaseDal.QueryFirst(x => x.Id != _PackType.Id && x.PackLength == _PackType.PackLength && x.PackWidth == _PackType.PackWidth && x.PackHeight == _PackType.PackHeight);
|
if( !temp.IsNotEmptyOrNull() )
|
{
|
saveModel.MainData["Remark"] = _PackType.PackLength + "*" + _PackType.PackWidth + "* " + _PackType.PackHeight;
|
return base.UpdateData(saveModel);
|
}
|
return WebResponseContent.Instance.Error($"修改失败,库存已存在该箱型!");
|
|
}
|
}
|
}
|