NewGaoKaoApi/New_College.Api/Controllers/Back/D_PlanMajorDescController.cs

77 lines
2.3 KiB
C#

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_PlanMajorDescController : ControllerBase
{
/// <summary>
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
/// </summary>
private readonly ID_PlanMajorDescServices _d_PlanMajorDescServices;
public D_PlanMajorDescController(ID_PlanMajorDescServices D_PlanMajorDescServices)
{
_d_PlanMajorDescServices = D_PlanMajorDescServices;
}
[HttpGet]
public async Task<MessageModel<PageModel<D_PlanMajorDesc>>> Get(int page = 1, string key = "", int intPageSize = 50)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
}
Expression<Func<D_PlanMajorDesc, bool>> whereExpression = a => a.Id > 0;
return new MessageModel<PageModel<D_PlanMajorDesc>>()
{
msg = "获取成功",
success = true,
response = await _d_PlanMajorDescServices.QueryPage(whereExpression, page, intPageSize)
};
}
[HttpGet("{id}")]
public async Task<MessageModel<D_PlanMajorDesc>> Get(int id = 0)
{
return new MessageModel<D_PlanMajorDesc>()
{
msg = "获取成功",
success = true,
response = await _d_PlanMajorDescServices.QueryById(id)
};
}
[HttpPost]
public async Task<MessageModel<string>> Post([FromBody] D_PlanMajorDesc request)
{
var data = new MessageModel<string>();
var id = await _d_PlanMajorDescServices.Add(request);
data.success = id > 0;
if (data.success)
{
data.response = id.ObjToString();
data.msg = "添加成功";
}
return data;
}
}
}