wangxinhui
2 天以前 011ca316e6ec2ed93e31c45a9ebd9d3c66664871
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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($"修改失败,库存已存在该箱型!");
 
        }
    }
}