DeviceRepository.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. //return await _context.WcsDevices.ToListAsync();
  25. }
  26. public async Task<List<WcsDevice>> GetDevicesAsync()
  27. {
  28. return await _context.WcsDevices.ToListAsync();
  29. }
  30. //所有使用设备
  31. public List<WcsDevice> GetDeviceAllList()
  32. {
  33. IQueryable<WcsDevice> devices = _context.WcsDevices;
  34. devices = devices.Where(x => x.UseState);
  35. return devices.ToList();
  36. }
  37. public List<WcsDevice> GetDevices()
  38. {
  39. IQueryable<WcsDevice> devices = _context.WcsDevices;
  40. return devices.ToList();
  41. }
  42. //查询设备详情
  43. public async Task<WcsDevice> GetDeviceById(int id)
  44. {
  45. WcsDevice device = await _context.WcsDevices.FindAsync(id);
  46. return device;
  47. }
  48. //添加详情
  49. public async Task<bool> CreateDevice(WcsDevice device)
  50. {
  51. _context.WcsDevices.Add(device);
  52. await _context.SaveChangesAsync();
  53. return true;
  54. }
  55. //更新详情
  56. public async Task<bool> UpdateDevice(WcsDevice device)
  57. {
  58. _context.Entry(device).State = EntityState.Modified;
  59. try
  60. {
  61. await _context.SaveChangesAsync();
  62. }
  63. catch (DbUpdateConcurrencyException)
  64. {
  65. throw;
  66. }
  67. return true;
  68. }
  69. }
  70. }