CourseService.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Furion.DatabaseAccessor.Extensions;
  2. using YBEE.EQM.Core;
  3. namespace YBEE.EQM.Application;
  4. /// <summary>
  5. /// 科目基础数据管理服务
  6. /// </summary>
  7. public class CourseService : ICourseService, ITransient
  8. {
  9. private readonly IRepository<Course> _rep;
  10. public CourseService(IRepository<Course> rep)
  11. {
  12. _rep = rep;
  13. }
  14. /// <summary>
  15. /// 添加科目
  16. /// </summary>
  17. /// <param name="input"></param>
  18. /// <returns></returns>
  19. public async Task Add(AddCourseInput input)
  20. {
  21. if (!await _rep.AnyAsync(t => t.Name == input.Name))
  22. {
  23. throw Oops.Oh(ErrorCode.E2005);
  24. }
  25. var item = input.Adapt<Course>();
  26. await item.InsertAsync();
  27. }
  28. /// <summary>
  29. /// 更新科目
  30. /// </summary>
  31. /// <param name="input"></param>
  32. /// <returns></returns>
  33. public async Task Update(UpdateCourseInput input)
  34. {
  35. if (!await _rep.AnyAsync(t => t.Id != input.Id && t.Name == input.Name))
  36. {
  37. throw Oops.Oh(ErrorCode.E2005);
  38. }
  39. var item = input.Adapt<Course>();
  40. await item.UpdateAsync();
  41. }
  42. /// <summary>
  43. /// 软删除科目
  44. /// </summary>
  45. /// <param name="input"></param>
  46. /// <returns></returns>
  47. public async Task Del(BaseId input)
  48. {
  49. var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001);
  50. await item.FakeDeleteNowAsync();
  51. }
  52. /// <summary>
  53. /// 根据ID获取单个科目
  54. /// </summary>
  55. /// <param name="id"></param>
  56. /// <returns></returns>
  57. public async Task<CourseOutput> GetById(int id)
  58. {
  59. var item = await _rep.FirstOrDefaultAsync(t => t.Id == id) ?? throw Oops.Oh(ErrorCode.E2001);
  60. return item.Adapt<CourseOutput>();
  61. }
  62. /// <summary>
  63. /// 获取全部科目完整信息列表
  64. /// </summary>
  65. /// <returns></returns>
  66. public async Task<List<CourseOutput>> GetAllList()
  67. {
  68. var items = await _rep.DetachedEntities.Where(t => t.Status == CommonStatus.ENABLE).ProjectToType<CourseOutput>().ToListAsync();
  69. return items;
  70. }
  71. /// <summary>
  72. /// 获取全部科目简要信息列表
  73. /// </summary>
  74. /// <returns></returns>
  75. public async Task<List<CourseLiteOutput>> GetAllLiteList()
  76. {
  77. var items = await _rep.DetachedEntities.Where(t => t.Status == CommonStatus.ENABLE).ProjectToType<CourseLiteOutput>().ToListAsync();
  78. return items;
  79. }
  80. }