平安校园
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.

BuildingService.cs 2.5 KiB

1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
1 miesiąc temu
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. var modelold = await GetFirstAsync(p => p.Name == input.Name);
  8. if (modelold != null)
  9. {
  10. throw Oops.Oh("宿舍楼已存在");
  11. }
  12. await InsertAsync(model);
  13. return true;
  14. }
  15. public async Task<bool> Update(BuildingInfoDto input)
  16. {
  17. if (!input.Id.HasValue)
  18. {
  19. throw Oops.Oh("请填写ID");
  20. }
  21. var modelold = await GetFirstAsync(p => p.Name == input.Name&&p.Id!=input.Id);
  22. if (modelold != null)
  23. {
  24. throw Oops.Oh("宿舍楼已存在");
  25. }
  26. var model = await GetFirstAsync(p => p.Id == input.Id);
  27. if (model == null)
  28. {
  29. throw Oops.Oh("信息不存在");
  30. }
  31. var res = input.Adapt(model);
  32. await UpdateAsync(res);
  33. return true;
  34. }
  35. public async Task<BuildingInfoDto> GetInfo(long id)
  36. {
  37. var model = await Context.Queryable<BuildingInfo>()
  38. .FirstAsync(x => x.Id == id);
  39. if (model == null)
  40. {
  41. return null;
  42. }
  43. return model.Adapt<BuildingInfoDto>();
  44. }
  45. public async Task<bool> Delete(long id)
  46. {
  47. var model = await GetFirstAsync(x => x.Id == id);
  48. if (model == null)
  49. {
  50. throw Oops.Oh("信息不存在");
  51. }
  52. var dor = ChangeRepository<DbRepository<DormitoryInfo>>();//切换仓储
  53. var build = await dor.GetListAsync(x=>x.BuildId==model.Id);
  54. if (build.Any())
  55. {
  56. throw Oops.Oh("宿舍楼下还有寝室不可删除!");
  57. }
  58. await DeleteAsync(model);
  59. return true;
  60. }
  61. public async Task<List<BuildingInfoDto>> GetNoPageList()
  62. {
  63. var list = await Context.Queryable<BuildingInfo>()
  64. .Includes(x => x.InsCameraInfoItem)
  65. .Includes(x => x.OutCameraInfoItem)
  66. .OrderBy(x=>x.CreateTime)
  67. .ToListAsync();
  68. //var list = await GetListAsync();
  69. return list.Adapt<List<BuildingInfoDto>>();
  70. }
  71. public async Task<List<string>> GetUseCameraList()
  72. {
  73. var list = await GetListAsync();
  74. var camera = new List<string>();
  75. camera.AddRange(list.Select(x=>x.InsCameraId));
  76. camera.AddRange(list.Select(x=>x.OutCameraId));
  77. return camera;
  78. }
  79. }