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

82 lines
2.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LinqKit;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.Models;
using New_College.Model.Request;
namespace New_College.Api.Controllers.Front
{
/// <summary>
/// 新高考选科
/// </summary>
[Route("api/[controller]")]
[ApiController]
//[Authorize]
public class FrontSelectionController : ControllerBase
{
private readonly ISubjectSelectionServices _selectionServices;
public FrontSelectionController(ISubjectSelectionServices subjectSelection)
{
this._selectionServices = subjectSelection;
}
/// <summary>
/// 根据院校和专业名称查询选科组合情况
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<PageModel<SubjectSelection>>> GetSubjectSelects([FromQuery] SelectionServiceRequest request)
{
try
{
var wheres = PredicateBuilder.New<SubjectSelection>();
if (request.UniversityName.Any())
{
request.UniversityName.ForEach(a => {
wheres = wheres.Or(x => x.UniversityName.Contains(a));
});
}
if (request.MajorName.Any())
{
request.UniversityName.ForEach(a => {
wheres = wheres.Or(x => x.MajorName.Contains(a));
});
}
var subjectlist = await _selectionServices.QueryPage(wheres, request.PageIndex, request.PageSize);
return new MessageModel<PageModel<SubjectSelection>>()
{
msg = "success",
response = subjectlist,
success = true
};
}
catch (Exception ex)
{
return new MessageModel<PageModel<SubjectSelection>>()
{
msg = ex.Message
};
}
}
}
}