Nie możesz wybrać więcej, niż 25 tematów
Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
|
- namespace SafeCampus.Application.Services.Business.BuildingService;
-
- public class BuildingService:DbRepository<BuildingInfo>,IBuildingService
- {
- public async Task<bool> Add(BuildingInfoDto input)
- {
- var model = input.Adapt<BuildingInfo>();
- var modelold = await GetFirstAsync(p => p.Name == input.Name);
- if (modelold != null)
- {
- throw Oops.Oh("宿舍楼已存在");
- }
- await InsertAsync(model);
- return true;
- }
-
- public async Task<bool> Update(BuildingInfoDto input)
- {
- if (!input.Id.HasValue)
- {
- throw Oops.Oh("请填写ID");
- }
- var modelold = await GetFirstAsync(p => p.Name == input.Name&&p.Id!=input.Id);
- if (modelold != null)
- {
- throw Oops.Oh("宿舍楼已存在");
- }
- var model = await GetFirstAsync(p => p.Id == input.Id);
- if (model == null)
- {
- throw Oops.Oh("信息不存在");
- }
- var res = input.Adapt(model);
- await UpdateAsync(res);
- return true;
- }
-
- public async Task<BuildingInfoDto> GetInfo(long id)
- {
- var model = await Context.Queryable<BuildingInfo>()
- .FirstAsync(x => x.Id == id);
- if (model == null)
- {
- return null;
- }
- return model.Adapt<BuildingInfoDto>();
- }
-
- public async Task<bool> Delete(long id)
- {
- var model = await GetFirstAsync(x => x.Id == id);
- if (model == null)
- {
- throw Oops.Oh("信息不存在");
- }
- var dor = ChangeRepository<DbRepository<DormitoryInfo>>();//切换仓储
- var build = await dor.GetListAsync(x=>x.BuildId==model.Id);
- if (build.Any())
- {
- throw Oops.Oh("宿舍楼下还有寝室不可删除!");
- }
- await DeleteAsync(model);
- return true;
- }
-
- public async Task<List<BuildingInfoDto>> GetNoPageList()
- {
- var list = await Context.Queryable<BuildingInfo>()
- .Includes(x => x.InsCameraInfoItem)
- .Includes(x => x.OutCameraInfoItem)
- .OrderBy(x=>x.CreateTime)
- .ToListAsync();
- //var list = await GetListAsync();
- return list.Adapt<List<BuildingInfoDto>>();
- }
-
- public async Task<List<string>> GetUseCameraList()
- {
- var list = await GetListAsync();
- var camera = new List<string>();
- camera.AddRange(list.Select(x=>x.InsCameraId));
- camera.AddRange(list.Select(x=>x.OutCameraId));
- return camera;
- }
- }
|