80 lines
3.0 KiB
C#
80 lines
3.0 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 System.Collections.Generic;
|
||
using New_College.Model.ViewModels;
|
||
using SqlSugar;
|
||
using System.Linq;
|
||
|
||
namespace New_College.Api.Controllers
|
||
{
|
||
[Route("api/[controller]/[action]")]
|
||
[ApiController]
|
||
[Authorize(Permissions.Name)]
|
||
public class HighSchoolRankController : ControllerBase
|
||
{
|
||
/// <summary>
|
||
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
|
||
/// </summary>
|
||
private readonly ID_HighSchoolRankServices _d_HighSchoolRankServices;
|
||
|
||
public HighSchoolRankController(ID_HighSchoolRankServices D_HighSchoolRankServices)
|
||
{
|
||
_d_HighSchoolRankServices = D_HighSchoolRankServices;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 获取高中学校名单
|
||
/// </summary>
|
||
/// <param name="highSchoolRank">通过省份名称当作过滤条件模糊查询学校名称</param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
public async Task<MessageModel<List<HighSchoolRankResponse>>> Get(HighSchoolRankRequest highSchoolRank)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(highSchoolRank.City))
|
||
{
|
||
return new MessageModel<List<HighSchoolRankResponse>>()
|
||
{
|
||
msg = "请传入省份或城市字段:City",
|
||
success = false
|
||
};
|
||
}
|
||
if (string.IsNullOrWhiteSpace(highSchoolRank.Province))
|
||
{
|
||
return new MessageModel<List<HighSchoolRankResponse>>()
|
||
{
|
||
msg = "请传入省份或城市字段:Province",
|
||
success = false
|
||
};
|
||
}
|
||
Expression<Func<D_HighSchoolRank, bool>> exp = Expressionable.Create<D_HighSchoolRank>()
|
||
.And(c => c.IsDelete == false)
|
||
.AndIF(!string.IsNullOrWhiteSpace(highSchoolRank.Province), c => c.Province == highSchoolRank.Province)
|
||
.AndIF(!string.IsNullOrWhiteSpace(highSchoolRank.City), c => c.City == highSchoolRank.City)
|
||
.AndIF(!string.IsNullOrWhiteSpace(highSchoolRank.Area), c => c.City == highSchoolRank.Area)
|
||
.AndIF(!string.IsNullOrWhiteSpace(highSchoolRank.Name), c => SqlFunc.Contains(highSchoolRank.Name, c.SchoolName))
|
||
.ToExpression();
|
||
var query = (await _d_HighSchoolRankServices.Query(exp)).Select(c => new HighSchoolRankResponse()
|
||
{
|
||
SchoolName = c.SchoolName,
|
||
Id = c.Id,
|
||
}).ToList();
|
||
|
||
return new MessageModel<List<HighSchoolRankResponse>>()
|
||
{
|
||
msg = "获取成功",
|
||
success = true,
|
||
response = query
|
||
};
|
||
|
||
}
|
||
|
||
}
|
||
} |