DeviceRepository.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 
  2. using IMCS.CCS.Entitys;
  3. using Microsoft.EntityFrameworkCore;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. namespace IMCS.CCS.Repository
  9. {
  10. public class DeviceRepository: IDeviceRepository
  11. {
  12. private readonly CcsContext _context;
  13. public DeviceRepository(CcsContext context)
  14. {
  15. _context = context;
  16. }
  17. //查询在线设备列表
  18. public List<Device> GetDeviceList()
  19. {
  20. IQueryable<Device> devices = _context.Device;
  21. devices = devices.Where(x => x.State && x.UseState && !x.ProtocolType.Equals(ProtocalTypeEnum.FTP.ToString()));
  22. return devices.ToList();
  23. }
  24. //所有使用设备
  25. public List<Device> GetDeviceAllList()
  26. {
  27. IQueryable<Device> devices = _context.Device;
  28. devices = devices.Where(x => x.UseState);
  29. return devices.ToList();
  30. }
  31. public List<Device> GetDevices()
  32. {
  33. IQueryable<Device> devices = _context.Device;
  34. return devices.ToList();
  35. }
  36. //查询设备详情
  37. public async Task<Device> GetDeviceById(int id)
  38. {
  39. Device device = await _context.Device.FindAsync(id);
  40. return device;
  41. }
  42. //添加详情
  43. public async Task<bool> CreateDevice(Device device)
  44. {
  45. _context.Device.Add(device);
  46. await _context.SaveChangesAsync();
  47. return true;
  48. }
  49. //更新详情
  50. public async Task<bool> UpdateDevice(Device device)
  51. {
  52. _context.Entry(device).State = EntityState.Modified;
  53. try
  54. {
  55. await _context.SaveChangesAsync();
  56. }
  57. catch (DbUpdateConcurrencyException)
  58. {
  59. throw;
  60. }
  61. return true;
  62. }
  63. }
  64. }