using GDZZ.Core; using Furion.DependencyInjection; using Furion.DynamicApiController; using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System.Linq; using System.Threading.Tasks; using GDZZ.Application.Entity; using GDZZ.Core.Entity; namespace GDZZ.Application { /// /// 课程表服务 /// [ApiDescriptionSettings("Application", Name = "Course", Order = 1)] public class CourseService : ICourseService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; public CourseService(SqlSugarRepository rep) { _rep = rep; } /// /// 分页查询课程表 /// /// /// [HttpGet("/Mini/Course/page")] public async Task Page([FromQuery] CourseInput input) { var entities = await _rep.AsQueryable() .InnerJoin((n, u) => n.FileID == u.Id) .WhereIF(!UserManager.IsTenantAdmin, n => n.CreatedUserId == UserManager.UserId) .WhereIF(!string.IsNullOrWhiteSpace(input.Tags), n => n.Tags == input.Tags) .WhereIF(!string.IsNullOrWhiteSpace(input.Title), n => n.Title == input.Title) .Select((n, u) => new CourseOutput { FileID = u.Id, Id = n.Id, Info = n.Info, Price = n.Price, Tags = n.Tags, Title = n.Title, Url = n.Url, VoiderUrl = "/"+u.FilePath+"/"+u.FileObjectName }) .ToPagedListAsync(input.PageNo, input.PageSize); return entities.XnPagedResult(); } /// /// 增加课程表 /// /// /// [HttpPost("/Mini/Course/page")] public async Task Add(AddCourseInput input) { var entity = input.Adapt(); await _rep.InsertAsync(entity); } /// /// 删除课程表 /// /// /// [HttpPost("/Course/delete")] public async Task Delete(DeleteCourseInput input) { var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id); await _rep.DeleteAsync(entity); } /// /// 更新课程表 /// /// /// [HttpPost("/Course/edit")] public async Task Update(UpdateCourseInput input) { var entity = input.Adapt(); await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } /// /// 获取课程表 /// /// /// [HttpGet("/Course/detail")] public async Task Get([FromQuery] QueryeCourseInput input) { return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id); } /// /// 获取课程表列表 /// /// /// [HttpGet("/Course/list")] public async Task List([FromQuery] CourseInput input) { return await _rep.ToListAsync(); } } }