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
{
///
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
///
private readonly IWMSupplier_TypeServices _wMSupplier_TypeServices;
public WMSupplier_TypeController(IWMSupplier_TypeServices WMSupplier_TypeServices)
{
_wMSupplier_TypeServices = WMSupplier_TypeServices;
}
[HttpGet]
public async Task>> Get(int page = 1, string key = "", int intPageSize = 20)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
}
Expression> whereExpression = a => a.Id > 0;
return new MessageModel>()
{
msg = "获取成功",
success = true,
response = await _wMSupplier_TypeServices.QueryPage(whereExpression, page, intPageSize)
};
}
[HttpPost]
public async Task> Post([FromBody] WMSupplier_Type request)
{
var data = new MessageModel();
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> Put([FromBody] WMSupplier_Type request)
{
var data = new MessageModel();
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> Delete(int Id = 0)
{
var data = new MessageModel();
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;
}
}
}