|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- namespace SafeCampus.Application.Services.Business.PersonSetInfoService;
-
- public class PersonSetInfoService:DbRepository<PersonSetInfo>, IPersonSetInfoService
- {
- public async Task<bool> Add(PersonSetInfoDto input)
- {
- var model = input.Adapt<PersonSetInfo>();
- var oldModel = await GetFirstAsync(x => x.PersonSetId == input.PersonSetId);
- if (oldModel != null)
- {
- throw Oops.Oh("该班级id已存在");
- }
- model.CreateTime=DateTime.Now;
- await InsertAsync(model);
- return true;
- }
-
- public async Task<bool> Delete(string id)
- {
- var model = await GetFirstAsync(x => x.PersonSetId == id);
- if (model == null)
- {
- throw Oops.Oh("信息不存在");
- }
- await DeleteAsync(model);
- return true;
- }
-
- public async Task<bool> Update(PersonSetInfoDto input)
- {
-
- var model = await GetFirstAsync(p => p.PersonSetId == input.PersonSetId);
- if (model == null)
- {
- throw Oops.Oh("信息不存在");
- }
- var res = input.Adapt(model);
- await UpdateAsync(res);
- return true;
- }
-
- public async Task<List<PersonSetInfoDto>> GetPageList(long? majorId, string setName)
- {
- var list =await Context.Queryable<PersonSetInfo>()
- .Includes(x=>x.MajorInfoItem,x=>x.DepartmentInfoItem)
- .Includes(x => x.ClassTeacherItem, st => st.SysUserItem)
- .Where(x=>x.PersonSetId!=SafeCampusConst.ZDRY)
- .WhereIF(majorId.HasValue,x=>x.MajorId==majorId)
- .WhereIF(!string.IsNullOrEmpty(setName),x=>x.PersonSetName.Contains(setName))
- .ToListAsync();
- return list.Adapt<List<PersonSetInfoDto>>();
- }
-
- public async Task<SqlSugarPagedList<PersonSetInfoDto>> GetList(PersonSetInfoSearch search)
- {
-
- var query = Context.Queryable<PersonSetInfo>()
- .Includes(x => x.MajorInfoItem, x => x.DepartmentInfoItem)
- .Includes(x => x.ClassTeacherItem, st => st.SysUserItem)
- .Where(x => x.PersonSetId != SafeCampusConst.ZDRY)
- .WhereIF(search.MajorId.HasValue, x => x.MajorId ==search.MajorId)
- .WhereIF(!string.IsNullOrEmpty(search.SetName), x => x.PersonSetName.Contains(search.SetName));
-
- var list = await query.OrderByDescending(x => x.CreateTime)
- .ToPagedListAsyncMapster<PersonSetInfo, PersonSetInfoDto>(search.PageNum, search.PageSize);
- return list;
- }
-
- public async Task<bool> CheckName(string name,string id)
- {
- var model =await GetFirstAsync(x => x.PersonSetName == name&&(string.IsNullOrEmpty(id) ||x.PersonSetId!=id));
- return model != null;
- }
- }
|