private DeviceDTO ToDTO(device s) { DeviceDTO dto = new DeviceDTO(); dto.device_ID = s.device_ID; if (s.department != null) { dto.device_dept = s.department.dept_name; } dto.device_info = s.device_info; dto.device_mark = s.device_mark; dto.device_name = s.device_name; return(dto); }
public int AddNew(string device_ID, string device_name) { using (MyContext ctx = new MyContext()) { var device = ctx.devices.SingleOrDefault(d => d.device_ID == device_ID); if (device == null) { device s = new device(); s.device_ID = device_ID; s.device_name = device_name; s.device_dept = null; s.device_mark = 0; ctx.devices.Add(s); ctx.SaveChanges(); return(1); } else { return(-1); } } }