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;
using System.Collections.Generic;
namespace GDZZ.Application
{
///
/// 课程表服务
///
[ApiDescriptionSettings("Application", Name = "Course", Order = 1)]
public class CourseService : ICourseService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly SqlSugarRepository sysFileRep;
public CourseService(SqlSugarRepository rep, SqlSugarRepository sysFileRep)
{
_rep = rep;
this.sysFileRep = sysFileRep;
}
///
/// 分页查询课程表
///
///
///
[HttpGet("/Mini/Course/page")]
public async Task Page([FromQuery] CourseInput input)
{
var entities = await _rep.AsQueryable()
.Includes(x=>x.SysFiles)
.Where(x=>x.SysFiles.Any(z=>z.FileSuffix == "mp4"))
.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)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加课程表
///
///
///
[HttpPost("/Mini/Course/add")]
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();
}
}
}