using Furion.DatabaseAccessor.Extensions; using YBEE.EQM.Core; namespace YBEE.EQM.Application; /// /// 科目基础数据管理服务 /// public class CourseService : ICourseService, ITransient { private readonly IRepository _rep; public CourseService(IRepository rep) { _rep = rep; } /// /// 添加科目 /// /// /// public async Task Add(AddCourseInput input) { if (!await _rep.AnyAsync(t => t.Name == input.Name)) { throw Oops.Oh(ErrorCode.E2005); } var item = input.Adapt(); await item.InsertAsync(); } /// /// 更新科目 /// /// /// public async Task Update(UpdateCourseInput input) { if (!await _rep.AnyAsync(t => t.Id != input.Id && t.Name == input.Name)) { throw Oops.Oh(ErrorCode.E2005); } var item = input.Adapt(); await item.UpdateAsync(); } /// /// 软删除科目 /// /// /// public async Task Del(BaseId input) { var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001); await item.FakeDeleteNowAsync(); } /// /// 根据ID获取单个科目 /// /// /// public async Task GetById(int id) { var item = await _rep.FirstOrDefaultAsync(t => t.Id == id) ?? throw Oops.Oh(ErrorCode.E2001); return item.Adapt(); } /// /// 获取全部科目完整信息列表 /// /// public async Task> GetAllList() { var items = await _rep.DetachedEntities.Where(t => t.Status == CommonStatus.ENABLE).ProjectToType().ToListAsync(); return items; } /// /// 获取全部科目简要信息列表 /// /// public async Task> GetAllLiteList() { var items = await _rep.DetachedEntities.Where(t => t.Status == CommonStatus.ENABLE).ProjectToType().ToListAsync(); return items; } }