using WCS.Entitys; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using WCS.Common; namespace WCS.Repository { public class DeviceRepository: IDeviceRepository { private readonly ApplicationDbContext _context; public DeviceRepository(ApplicationDbContext context) { _context = context; } //查询在线设备列表 public List GetDeviceList() { IQueryable devices = _context.WcsDevices; devices = devices.Where(x => x.State && x.UseState); return devices.ToList(); //return await _context.WcsDevices.ToListAsync(); } public async Task> GetDevicesAsync() { return await _context.WcsDevices.ToListAsync(); } //所有使用设备 public List GetDeviceAllList() { IQueryable devices = _context.WcsDevices; devices = devices.Where(x => x.UseState); return devices.ToList(); } public List GetDevices() { IQueryable devices = _context.WcsDevices; return devices.ToList(); } //查询设备详情 public async Task GetDeviceById(int id) { WcsDevice device = await _context.WcsDevices.FindAsync(id); return device; } //添加详情 public async Task CreateDevice(WcsDevice device) { _context.WcsDevices.Add(device); await _context.SaveChangesAsync(); return true; } //更新详情 public async Task UpdateDevice(WcsDevice device) { _context.Entry(device).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return true; } } }