ExamPaperQuestionMinorService.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Furion.DatabaseAccessor.Extensions;
  2. using Microsoft.VisualBasic;
  3. using YBEE.EQM.Core;
  4. namespace YBEE.EQM.Application;
  5. /// <summary>
  6. /// 试卷小题管理服务
  7. /// </summary>
  8. public class ExamPaperQuestionMinorService : IExamPaperQuestionMinorService, ITransient
  9. {
  10. private readonly IRepository<ExamPaperQuestionMinor> _rep;
  11. public ExamPaperQuestionMinorService(IRepository<ExamPaperQuestionMinor> rep)
  12. {
  13. _rep = rep;
  14. }
  15. /// <summary>
  16. /// 添加
  17. /// </summary>
  18. /// <param name="input"></param>
  19. /// <returns></returns>
  20. public async Task Add(AddExamPaperQuestionMinorInput input)
  21. {
  22. var item = input.Adapt<ExamPaperQuestionMinor>();
  23. await _rep.InsertNowAsync(item);
  24. }
  25. /// <summary>
  26. /// 更新
  27. /// </summary>
  28. /// <param name="input"></param>
  29. /// <returns></returns>
  30. public async Task Update(UpdateExamPaperQuestionMinorInput input)
  31. {
  32. var item = input.Adapt<ExamPaperQuestionMinor>();
  33. if (!await _rep.AnyAsync(t => t.Id == input.Id))
  34. {
  35. throw Oops.Oh(ErrorCode.E2001, "试卷小题");
  36. }
  37. await item.UpdateAsync();
  38. }
  39. /// <summary>
  40. /// 批量更新
  41. /// </summary>
  42. /// <param name="input"></param>
  43. /// <returns></returns>
  44. public async Task BatchUpdate(BatchUpdateExamPaperQuestionMinorInput input)
  45. {
  46. var items = await _rep.Where(t => input.Ids.Contains(t.Id)).ToListAsync();
  47. foreach (var item in items)
  48. {
  49. item.ExamPaperQuestionMajorId = input.ExamPaperQuestionMajorId;
  50. item.Score = input.Score;
  51. item.QuestionCatalog = input.QuestionCatalog;
  52. }
  53. await _rep.UpdateAsync();
  54. }
  55. /// <summary>
  56. /// 删除
  57. /// </summary>
  58. /// <param name="input"></param>
  59. /// <returns></returns>
  60. public async Task Del(BaseId input)
  61. {
  62. var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001, "试卷小题");
  63. await _rep.DeleteAsync(item);
  64. }
  65. /// <summary>
  66. /// 根据试卷ID获取小题列表
  67. /// </summary>
  68. /// <param name="examPaperId"></param>
  69. /// <returns></returns>
  70. public async Task<List<ExamPaperQuestionMinorOutput>> GetListByExamPaperId(int examPaperId)
  71. {
  72. var items = await _rep.DetachedEntities.Where(t => t.ExamPaperId == examPaperId).ProjectToType<ExamPaperQuestionMinorOutput>().OrderBy(t => t.Sequence).ToListAsync();
  73. return items;
  74. }
  75. }