DeviceRepository.cs 1.9 KB

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