using Admin.NET.Core; using Furion.DatabaseAccessor; using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; namespace Admin.NET.Application { /// /// 特殊批次招生服务 /// [ApiDescriptionSettings("测评服务", Name = "BusSpecialRecruitStudents", Order = 100)] public class BusSpecialRecruitStudentsService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _busSpecialRecruitStudentsRep; /// /// /// /// public BusSpecialRecruitStudentsService( SqlSugarRepository busSpecialRecruitStudentsRep ) { _busSpecialRecruitStudentsRep = busSpecialRecruitStudentsRep; } /// /// 分页查询特殊批次招生 /// /// /// [HttpGet("page")] [AllowAnonymous] public async Task> Page([FromQuery] BusSpecialRecruitStudentsInput input) { var busSpecialRecruitStudentss = await _busSpecialRecruitStudentsRep.AsQueryable() .WhereIF(!string.IsNullOrEmpty(input.Title), u => u.Title == input.Title) .WhereIF(!string.IsNullOrEmpty(input.Pic), u => u.Pic == input.Pic) .WhereIF(!string.IsNullOrEmpty(input.Summary), u => u.Summary == input.Summary) .WhereIF(!string.IsNullOrEmpty(input.Url), u => u.Url == input.Url) //.Where(u => u.Sort == input.Sort) .OrderBy(u => u.CreateTime, OrderByType.Desc) .OrderBuilder(input) .Select(s => new BusSpecialRecruitStudentsOutput() { Title = s.Title, Pic = s.Pic, Summary = s.Summary, Url = s.Url, Ico = s.Ico, Sort = s.Sort, Id = s.Id }) .ToPagedListAsync(input.Page, input.PageSize); return busSpecialRecruitStudentss; } /// /// 增加特殊批次招生 /// /// /// [HttpPost("add")] public async Task Add(AddBusSpecialRecruitStudentsInput input) { var busSpecialRecruitStudents = input.Adapt(); await _busSpecialRecruitStudentsRep.InsertAsync(busSpecialRecruitStudents); } /// /// 删除特殊批次招生 /// /// /// [HttpPost("delete")] public async Task Delete(DeleteBusSpecialRecruitStudentsInput input) { var busSpecialRecruitStudents = await _busSpecialRecruitStudentsRep.AsQueryable().FirstAsync(u => u.Id == input.Id); await _busSpecialRecruitStudentsRep.FakeDeleteAsync(busSpecialRecruitStudents); } /// /// 更新特殊批次招生 /// /// /// [HttpPost("edit")] public async Task Update(UpdateBusSpecialRecruitStudentsInput input) { var isExist = await _busSpecialRecruitStudentsRep.AsQueryable().AnyAsync(u => u.Id == input.Id); if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000); var busSpecialRecruitStudents = input.Adapt(); await _busSpecialRecruitStudentsRep.UpdateAsync(busSpecialRecruitStudents); } /// /// 获取特殊批次招生 /// /// /// [HttpGet("detail")] [AllowAnonymous] public async Task Get([FromQuery] QueryeBusSpecialRecruitStudentsInput input) { return (await _busSpecialRecruitStudentsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt(); } /// /// 获取特殊批次招生列表 /// /// /// [HttpGet("list")] [AllowAnonymous] public async Task> List([FromQuery] BusSpecialRecruitStudentsInput input) { return await _busSpecialRecruitStudentsRep.AsQueryable().Select().ToListAsync(); } } }