平安校园
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

65 righe
1.9 KiB

  1. namespace SafeCampus.Application.Services.Business.BuildingService;
  2. public class BuildingService:DbRepository<BuildingInfo>,IBuildingService
  3. {
  4. public async Task<bool> Add(BuildingInfoDto input)
  5. {
  6. var model = input.Adapt<BuildingInfo>();
  7. await InsertAsync(model);
  8. return true;
  9. }
  10. public async Task<bool> Update(BuildingInfoDto input)
  11. {
  12. if (!input.Id.HasValue)
  13. {
  14. throw Oops.Oh("请填写ID");
  15. }
  16. var model = await GetFirstAsync(p => p.Id == input.Id);
  17. if (model == null)
  18. {
  19. throw Oops.Oh("信息不存在");
  20. }
  21. var res = input.Adapt(model);
  22. await UpdateAsync(res);
  23. return true;
  24. }
  25. public async Task<BuildingInfoDto> GetInfo(long id)
  26. {
  27. var model = await Context.Queryable<BuildingInfo>()
  28. .FirstAsync(x => x.Id == id);
  29. if (model == null)
  30. {
  31. return null;
  32. }
  33. return model.Adapt<BuildingInfoDto>();
  34. }
  35. public async Task<bool> Delete(long id)
  36. {
  37. var model = await GetFirstAsync(x => x.Id == id);
  38. if (model == null)
  39. {
  40. throw Oops.Oh("信息不存在");
  41. }
  42. var dor = ChangeRepository<DbRepository<DormitoryInfo>>();//切换仓储
  43. var build = await dor.GetListAsync(x=>x.BuildId==model.Id);
  44. if (build.Any())
  45. {
  46. throw Oops.Oh("宿舍楼下还有寝室不可删除!");
  47. }
  48. await DeleteAsync(model);
  49. return true;
  50. }
  51. public async Task<List<BuildingInfoDto>> GetNoPageList()
  52. {
  53. var list = await Context.Queryable<BuildingInfo>()
  54. .Includes(x => x.InsCameraInfoItem)
  55. .Includes(x => x.OutCameraInfoItem)
  56. .ToListAsync();
  57. //var list = await GetListAsync();
  58. return list.Adapt<List<BuildingInfoDto>>();
  59. }
  60. }