using Furion.DatabaseAccessor.Extensions;
using Microsoft.VisualBasic;
using YBEE.EQM.Core;
namespace YBEE.EQM.Application;
///
/// 试卷小题管理服务
///
public class ExamPaperQuestionMinorService : IExamPaperQuestionMinorService, ITransient
{
private readonly IRepository _rep;
public ExamPaperQuestionMinorService(IRepository rep)
{
_rep = rep;
}
///
/// 添加
///
///
///
public async Task Add(AddExamPaperQuestionMinorInput input)
{
var item = input.Adapt();
await _rep.InsertNowAsync(item);
}
///
/// 更新
///
///
///
public async Task Update(UpdateExamPaperQuestionMinorInput input)
{
var item = input.Adapt();
if (!await _rep.AnyAsync(t => t.Id == input.Id))
{
throw Oops.Oh(ErrorCode.E2001, "试卷小题");
}
await item.UpdateAsync();
}
///
/// 批量更新
///
///
///
public async Task BatchUpdate(BatchUpdateExamPaperQuestionMinorInput input)
{
var items = await _rep.Where(t => input.Ids.Contains(t.Id)).ToListAsync();
foreach (var item in items)
{
item.ExamPaperQuestionMajorId = input.ExamPaperQuestionMajorId;
item.Score = input.Score;
item.QuestionCatalog = input.QuestionCatalog;
}
await _rep.UpdateAsync();
}
///
/// 删除
///
///
///
public async Task Del(BaseId input)
{
var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001, "试卷小题");
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;
}
}