123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
-
- 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<WcsDevice> GetDeviceList()
- {
- IQueryable<WcsDevice> devices = _context.WcsDevices;
- devices = devices.Where(x => x.State && x.UseState);
- return devices.ToList();
-
- //return await _context.WcsDevices.ToListAsync();
- }
- public async Task<List<WcsDevice>> GetDevicesAsync()
- {
- return await _context.WcsDevices.ToListAsync();
- }
- //所有使用设备
- public List<WcsDevice> GetDeviceAllList()
- {
- IQueryable<WcsDevice> devices = _context.WcsDevices;
- devices = devices.Where(x => x.UseState);
- return devices.ToList();
- }
- public List<WcsDevice> GetDevices()
- {
- IQueryable<WcsDevice> devices = _context.WcsDevices;
-
- return devices.ToList();
- }
- //查询设备详情
- public async Task<WcsDevice> GetDeviceById(int id)
- {
- WcsDevice device = await _context.WcsDevices.FindAsync(id);
- return device;
- }
- //添加详情
- public async Task<bool> CreateDevice(WcsDevice device)
- {
- _context.WcsDevices.Add(device);
- await _context.SaveChangesAsync();
- return true;
- }
- //更新详情
- public async Task<bool> UpdateDevice(WcsDevice device)
- {
- _context.Entry(device).State = EntityState.Modified;
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
-
- throw;
- }
- return true;
- }
-
-
- }
- }
|