NewGaoKaoApi/New_College.Api/Controllers/Front/HighSchoolRankController.cs

80 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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]
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([FromQuery] 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.Area == 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
};
}
}
}