using YBEE.EQM.Core; namespace YBEE.EQM.Application; /// /// 试卷大题管理服务 /// public class ExamPaperQuestionMajorService : IExamPaperQuestionMajorService, ITransient { private readonly IRepository _rep; public ExamPaperQuestionMajorService(IRepository rep) { _rep = rep; } /// /// 添加 /// /// /// public async Task Add(AddExamPaperQuestionMajorInput input) { var item = input.Adapt(); await _rep.InsertNowAsync(item); } /// /// 更新 /// /// /// public async Task Update(UpdateExamPaperQuestionMajorInput input) { var item = input.Adapt(); if (!await _rep.AnyAsync(t => t.Id == item.Id)) { throw Oops.Oh(ErrorCode.E2001, "试卷大题"); } await _rep.UpdateAsync(item); } /// /// 删除 /// /// /// public async Task Del(BaseId input) { var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001, "试卷大题"); if (await _rep.Change().AnyAsync(t => t.ExamPaperQuestionMajorId == input.Id)) { var ms = await _rep.Change().Where(t => t.ExamPaperQuestionMajorId == input.Id).ToListAsync(); foreach (var m in ms) { m.ExamPaperQuestionMajorId = null; } await _rep.Change().UpdateAsync(ms); } await _rep.DeleteAsync(item); } /// /// 根据试卷ID获取大题列表 /// /// /// public async Task> GetListByExamPaperId(int examPaperId) { var items = await _rep.DetachedEntities.Where(t => t.ExamPaperId == examPaperId).ProjectToType().OrderBy(t => t.Sequence).ToListAsync(); return items; } }