internal bool DeleteAreaDevice(AreaDevice areadev) { string sql = string.Format("DELETE FROM `area_device` where id = '{0}'", areadev.id); int row = mSql.ExcuteSql(sql); return(row >= 1); }
internal bool AddAreaDevice(AreaDevice areadev) { string str = "INSERT INTO `area_device`(`area_id`, `device_id`, `dev_type`) VALUES('{0}', '{1}', '{2}')"; string sql = string.Format(@str, areadev.area_id, areadev.device_id, areadev.dev_type); int row = mSql.ExcuteSql(sql); return(row >= 1); }
internal bool EditAreaDevice(AreaDevice areadev) { string sql = "UPDATE `area_device` set area_id = '{0}', `device_id` = {1} where id = '{2}'"; sql = string.Format(sql, areadev.area_id, areadev.device_id, areadev.id); int row = mSql.ExcuteSql(sql); return(row >= 1); }
private void UpdateObject(AreaDevice _newAreaDevice, ref AreaDevice _oldAreaDevice) { try { foreach (PropertyInfo AreaDevicePropInfo in _newAreaDevice.GetType().GetProperties().ToList()) { _oldAreaDevice.GetType().GetProperty(AreaDevicePropInfo.Name).SetValue(_oldAreaDevice, _newAreaDevice.GetType().GetProperty(AreaDevicePropInfo.Name).GetValue(_newAreaDevice)); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public AreaDevice AddNewAreaDevice(AreaDevice _AreaDevice) { try { using (var context = new VeraEntities()) { context.AreaDevice.Add(_AreaDevice); int numOfInserted = context.SaveChanges(); return(numOfInserted > 0 ? _AreaDevice : null); } } catch (Exception) { throw; } }
public AreaDevice UpdateAreaDevice(AreaDevice _AreaDevice) { try { using (var context = new VeraEntities()) { var oldAreaDevice = context.AreaDevice.FirstOrDefault(u => u.Id == _AreaDevice.Id); if (oldAreaDevice != null) { UpdateObject(_AreaDevice, ref oldAreaDevice); var numberOfUpdatedAreaDevice = context.SaveChanges(); return(numberOfUpdatedAreaDevice > 0 ? _AreaDevice : null); } return(null); } } catch (Exception e) { Console.WriteLine(e); throw; } }