1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
-
- using IMCS.CCS.Entitys;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- namespace IMCS.CCS.Repository
- {
- public class DeviceRepository: IDeviceRepository
- {
- private readonly CcsContext _context;
- public DeviceRepository(CcsContext context)
- {
- _context = context;
- }
- //查询在线设备列表
- public List<Device> GetDeviceList()
- {
- IQueryable<Device> devices = _context.Device;
- devices = devices.Where(x => x.State && x.UseState && !x.ProtocolType.Equals(ProtocalTypeEnum.FTP.ToString()));
- return devices.ToList();
- }
- //所有使用设备
- public List<Device> GetDeviceAllList()
- {
- IQueryable<Device> devices = _context.Device;
- devices = devices.Where(x => x.UseState);
- return devices.ToList();
- }
- public List<Device> GetDevices()
- {
- IQueryable<Device> devices = _context.Device;
-
- return devices.ToList();
- }
- //查询设备详情
- public async Task<Device> GetDeviceById(int id)
- {
- Device device = await _context.Device.FindAsync(id);
- return device;
- }
- //添加详情
- public async Task<bool> CreateDevice(Device device)
- {
- _context.Device.Add(device);
- await _context.SaveChangesAsync();
- return true;
- }
- //更新详情
- public async Task<bool> UpdateDevice(Device device)
- {
- _context.Entry(device).State = EntityState.Modified;
- try
- {
- await _context.SaveChangesAsync();
- }
- catch (DbUpdateConcurrencyException)
- {
-
- throw;
- }
- return true;
- }
-
-
- }
- }
|