namespace SafeCampus.Application.Services.Business.BuildingService; public class BuildingService:DbRepository,IBuildingService { public async Task Add(BuildingInfoDto input) { var model = input.Adapt(); var modelold = await GetFirstAsync(p => p.Name == input.Name); if (modelold != null) { throw Oops.Oh("宿舍楼已存在"); } await InsertAsync(model); return true; } public async Task Update(BuildingInfoDto input) { if (!input.Id.HasValue) { throw Oops.Oh("请填写ID"); } 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 GetInfo(long id) { var model = await Context.Queryable() .FirstAsync(x => x.Id == id); if (model == null) { return null; } return model.Adapt(); } public async Task Delete(long id) { var model = await GetFirstAsync(x => x.Id == id); if (model == null) { throw Oops.Oh("信息不存在"); } var dor = ChangeRepository>();//切换仓储 var build = await dor.GetListAsync(x=>x.BuildId==model.Id); if (build.Any()) { throw Oops.Oh("宿舍楼下还有寝室不可删除!"); } await DeleteAsync(model); return true; } public async Task> GetNoPageList() { var list = await Context.Queryable() .Includes(x => x.InsCameraInfoItem) .Includes(x => x.OutCameraInfoItem) .OrderBy(x=>x.CreateTime) .ToListAsync(); //var list = await GetListAsync(); return list.Adapt>(); } public async Task> GetUseCameraList() { var list = await GetListAsync(); var camera = new List(); camera.AddRange(list.Select(x=>x.InsCameraId)); camera.AddRange(list.Select(x=>x.OutCameraId)); return camera; } }