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
{
///
/// 服务器接口,因为是模板生成,所以首字母是大写的,自己可以重构下
///
private readonly ID_HighSchoolRankServices _d_HighSchoolRankServices;
public HighSchoolRankController(ID_HighSchoolRankServices D_HighSchoolRankServices)
{
_d_HighSchoolRankServices = D_HighSchoolRankServices;
}
///
/// 获取高中学校名单
///
/// 通过省份名称当作过滤条件模糊查询学校名称
///
[HttpGet]
public async Task>> Get(HighSchoolRankRequest highSchoolRank)
{
if (string.IsNullOrWhiteSpace(highSchoolRank.City))
{
return new MessageModel>()
{
msg = "请传入省份或城市字段:City",
success = false
};
}
if (string.IsNullOrWhiteSpace(highSchoolRank.Province))
{
return new MessageModel>()
{
msg = "请传入省份或城市字段:Province",
success = false
};
}
Expression> exp = Expressionable.Create()
.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>()
{
msg = "获取成功",
success = true,
response = query
};
}
}
}