namespace Tiobon.Core.Api.Controllers; /// /// Ghre_CourseClass(Controller) /// [Route("api/[controller]")] [ApiController, GlobalActionFilter] [Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)] public class Ghre_CourseClassController : BaseController { public Ghre_CourseClassController(IGhre_CourseClassServices service) : base(service) { } } //using SqlSugar; //using Mapper = AgileObjects.AgileMapper.Mapper; //namespace Tiobon.Core.Api.Controllers; ///// ///// 课程分类(Controller) ///// //[Route("api/[controller]")] //[ApiController, GlobalActionFilter] //[Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Ghre)] //public class Ghre_CourseClassController : BaseApiController //{ // protected IGhre_CourseClassServices _service; // public Ghre_CourseClassController(IGhre_CourseClassServices service) // { // _service = service; // } // #region 基础接口 // #region 查询 // /// // /// 根据条件查询数据 // /// // /// 条件 // /// // [HttpGet] // public async Task> QueryByFilter([FromFilter] QueryFilter filter) // { // //var data = await _service.QueryFilterPage(); // RefAsync totalCount = 0; // var query = _service.Db.Queryable(); // if (!filter.Conditions.IsNullOrEmpty()) // query = query.Where(filter.Conditions); // var list = await query // .OrderByIF(!string.IsNullOrEmpty(filter.Sorting), filter.Sorting) // .ToPageListAsync(filter.PageIndex, filter.PageSize, totalCount); // return new ServicePageResult1(filter.PageIndex, totalCount, filter.PageSize, Mapper.Map(list).ToANew>()); // } // public static T ConvertTo(object input) // { // if (input == null) // { // throw new ArgumentNullException(nameof(input)); // } // // 当T是Nullable类型时,需要获取其基础类型 // Type targetType = typeof(T); // Type nullableType = Nullable.GetUnderlyingType(targetType); // targetType = nullableType ?? targetType; // // 检查input是否已经是T类型 // if (input is T) // { // return (T)input; // } // // 尝试转换 // try // { // return (T)Convert.ChangeType(input, targetType); // } // catch (InvalidCastException) // { // throw new InvalidOperationException($"Cannot convert an instance of type {input.GetType().Name} to type {typeof(T).Name}."); // } // } // /// // /// 根据Id查询数据 // /// // /// 主键ID // /// // [HttpGet("{Id}")] // public virtual async Task> QueryById(long Id) // { // var entity1 = await _service.QueryById(Id); // var entity = ConvertTo(entity1); // if (entity is null) // return new ServiceResult() { Success = false, Status = 500, Message = "获取失败", Data = default }; // else // return new ServiceResult() { Success = false, Message = "获取成功", Data = entity }; // } // #endregion // #region 新增 // /// // /// 新增数据 // /// // /// // /// // [HttpPost] // public virtual async Task> Insert([FromBody] InsertGhre_CourseClassInput insertModel) // { // var data = new ServiceResult() { Success = true, Message = "新增成功", Data = null }; // var id = await _service.Add(insertModel); // data.Success = id > 0; // if (data.Success) // data.Data = id.ObjToString(); // else // return new ServiceResult() { Success = false, Status = 500, Message = "新增失败", Data = default }; // return data; // } // /// // /// 批量新增数据 // /// // /// // [HttpPost, Route("BulkInsert")] // public virtual async Task>> BulkInsert([FromBody] List insertModels) // { // var data = new ServiceResult>() { Success = true, Message = "新增成功", Data = null }; // var ids = await _service.Add(insertModels); // data.Success = ids.Any(); // if (data.Success) // data.Data = ids; // else // return new ServiceResult>() { Success = false, Status = 500, Message = "新增失败", Data = default }; // return data; // } // #endregion // #region 更新 // /// // /// 更新数据 // /// // /// 主键ID // /// // /// // [HttpPut("{Id}")] // public virtual async Task Put(long Id, [FromBody] EditGhre_CourseClassInput editModel) // { // var data = new ServiceResult() { Success = true, Message = "更新成功", Data = null }; // var flag = await _service.Update(Id, editModel); // if (!flag) // return new ServiceResult() { Success = false, Status = 500, Message = "更新失败", Data = default }; // return data; // } // /// // /// 批量更新数据 // /// // /// // [HttpPut, Route("BulkUpdate")] // public virtual async Task BulkUpdate([FromBody] Dictionary editModels) // { // var data = new ServiceResult() { Success = true, Message = "更新成功", Data = null }; // var flag = await _service.Update(editModels); // if (!flag) // return new ServiceResult() { Success = false, Status = 500, Message = "更新失败", Data = default }; // return data; // } // #endregion // #region 删除 // /// // /// 删除数据 // /// // /// 主键ID // /// // [HttpDelete("{Id}")] // public virtual async Task Delete(long Id) // { // var data = new ServiceResult() { Success = true, Message = "删除成功", Data = null }; // var isExist = await _service.AnyAsync(Id); // if (!isExist) // return new ServiceResult() { Success = false, Status = 500, Message = "无效的数据ID", Data = default }; // data.Success = await _service.DeleteById1(Id); ; // if (!data.Success) // return new ServiceResult() { Success = false, Status = 500, Message = "删除失败", Data = default }; // return data; // } // /// // /// 批量删除数据 // /// // /// 主键IDs // /// // [HttpDelete, Route("BulkDelete")] // public virtual async Task BulkDelete([FromBody] long[] Ids) // { // var data = new ServiceResult() { Success = true, Message = "删除成功", Data = null }; // data.Success = await _service.DeleteById1(Ids); // if (!data.Success) // return new ServiceResult() { Success = false, Status = 500, Message = "删除失败", Data = default }; // return data; // } // #endregion // #endregion //} ///// ///// 服务层分页响应实体(泛型) ///// //public class ServicePageResult1 //{ // /// // /// 状态码 // /// // public int Status { get; set; } = 200; // /// // /// 操作是否成功 // /// // public bool Success { get; set; } = false; // /// // /// 返回信息 // /// // public string Message { get; set; } = null; // /// // /// 当前页标 // /// // public int Page { get; set; } = 1; // /// // /// 总页数 // /// // public int PageCount => (int)Math.Ceiling((decimal)TotalCount / PageSize); // /// // /// 数据总数 // /// // public int TotalCount { get; set; } = 0; // /// // /// 每页大小 // /// // public int PageSize { set; get; } = 20; // /// // /// 返回数据 // /// // public List Data { get; set; } // public ServicePageResult1() { } // public ServicePageResult1(int page, int totalCount, int pageSize, List data) // { // Success = true; // this.Page = page; // this.TotalCount = totalCount; // PageSize = pageSize; // this.Data = data; // } //}