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

83 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;
using Microsoft.AspNetCore.Hosting;
using New_College.Common;
using System.IO;
using System.Linq;
namespace New_College.Api.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize(Permissions.Name)]
public class D_ScoreLineController : ControllerBase
{
/// <summary>
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
/// </summary>
private readonly ID_ScoreLineServices _d_ScoreLineServices;
public D_ScoreLineController(ID_ScoreLineServices D_ScoreLineServices)
{
_d_ScoreLineServices = D_ScoreLineServices;
}
[HttpGet]
public async Task<MessageModel<PageModel<D_ScoreLine>>> Get(int page = 1, string key = "", int intPageSize = 50)
{
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
}
Expression<Func<D_ScoreLine, bool>> whereExpression = a => a.Id > 0;
return new MessageModel<PageModel<D_ScoreLine>>()
{
msg = "获取成功",
success = true,
response = await _d_ScoreLineServices.QueryPage(whereExpression, page, intPageSize)
};
}
[HttpGet("{id}")]
public async Task<MessageModel<D_ScoreLine>> Get(int id = 0)
{
return new MessageModel<D_ScoreLine>()
{
msg = "获取成功",
success = true,
response = await _d_ScoreLineServices.QueryById(id)
};
}
[HttpPost]
public async Task<MessageModel<string>> Post([FromBody] D_ScoreLine request)
{
var data = new MessageModel<string>();
var id = await _d_ScoreLineServices.Add(request);
data.success = id > 0;
if (data.success)
{
data.response = id.ObjToString();
data.msg = "添加成功";
}
return data;
}
}
}