using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace New_College.Api.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
public class D_QualificationLineController : ControllerBase
{
///
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
///
private readonly ID_QualificationLineServices _d_QualificationLineServices;
public D_QualificationLineController(ID_QualificationLineServices D_QualificationLineServices)
{
_d_QualificationLineServices = D_QualificationLineServices;
}
[HttpGet]
public async Task>> Get(int page = 1, string key = "", int intPageSize = 50)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
}
Expression> whereExpression = a => a.Id > 0;
return new MessageModel>()
{
msg = "获取成功",
success = true,
response = await _d_QualificationLineServices.QueryPage(whereExpression, page, intPageSize)
};
}
[HttpGet("{id}")]
public async Task> Get(int id = 0)
{
return new MessageModel()
{
msg = "获取成功",
success = true,
response = await _d_QualificationLineServices.QueryById(id)
};
}
[HttpPost]
public async Task> Post([FromBody] D_QualificationLine request)
{
var data = new MessageModel();
var id = await _d_QualificationLineServices.Add(request);
data.success = id > 0;
if (data.success)
{
data.response = id.ObjToString();
data.msg = "添加成功";
}
return data;
}
}
}