WYB
2021-03-22 91b8cdad021ab052e4991f3d41834a6f0ddc36b8
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using JiepeiWMS.IServices;
using JiepeiWMS.Model;
using JiepeiWMS.Model.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
 
namespace JiepeiWMS.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize(Permissions.Name)]
    public class WMSupplier_TypeController : ControllerBase
    {
        /// <summary>
        /// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
        /// </summary>
        private readonly IWMSupplier_TypeServices _wMSupplier_TypeServices;
 
        public WMSupplier_TypeController(IWMSupplier_TypeServices WMSupplier_TypeServices)
        {
            _wMSupplier_TypeServices = WMSupplier_TypeServices;
        }
 
        [HttpGet]
        public async Task<MessageModel<PageModel<WMSupplier_Type>>> Get(int page = 1, string key = "", int intPageSize = 20)
        {
            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                key = "";
            }
 
            Expression<Func<WMSupplier_Type, bool>> whereExpression = a => a.Id > 0;
 
            return new MessageModel<PageModel<WMSupplier_Type>>()
            {
                msg = "获取成功",
                success = true,
                response = await _wMSupplier_TypeServices.QueryPage(whereExpression, page, intPageSize)
            };
 
        }
 
        [HttpPost]
        public async Task<MessageModel<string>> Post([FromBody] WMSupplier_Type request)
        {
            var data = new MessageModel<string>();
 
            var Id = await _wMSupplier_TypeServices.Add(request);
            data.success = Id > 0;
 
            if (data.success)
            {
                data.response = Id.ObjToString();
                data.msg = "添加成功";
            }
 
            return data;
        }
 
        [HttpPut]
        public async Task<MessageModel<string>> Put([FromBody] WMSupplier_Type request)
        {
            var data = new MessageModel<string>();
            if (request.Id > 0)
            {
                data.success = await _wMSupplier_TypeServices.Update(request);
                if (data.success)
                {
                    data.msg = "更新成功";
                    data.response = request?.Id.ObjToString();
                }
            }
 
            return data;
        }
 
        [HttpDelete("{Id}")]
        public async Task<MessageModel<string>> Delete(int Id = 0)
        {
            var data = new MessageModel<string>();
            if (Id > 0)
            {
                var detail = await _wMSupplier_TypeServices.QueryById(Id);
 
                detail.IsDeleted = true;
 
                if (detail != null)
                {
                    data.success = await _wMSupplier_TypeServices.Update(detail);
                    if (data.success)
                    {
                        data.msg = "删除成功";
                        data.response = detail?.Id.ObjToString();
                    }
                }
            }
 
            return data;
        }
    }
}