public SensorModels Add(SensorModels item) { try { using (SensorEntities _entity = new SensorEntities()) { Sensor sensor = new Sensor { Id = item.Id, Nome = item.Nome, idPais = item.PaisModels.Id, idRegiao = item.RegiaoModels.Id }; _entity.Entry(sensor).State = !_entity.Sensor.Any(f => f.Id == item.Id) ? EntityState.Added : EntityState.Modified; _entity.SaveChanges(); item.Id = sensor.Id; } } catch (Exception e) { throw new ArgumentNullException(e.Message, Mensagem.HOUVEUMERRONAEXECUCAO.GetStringValue()); } return(item); }
public PaisModels Add(PaisModels item) { try { using (SensorEntities _entity = new SensorEntities()) { Pais pais = new Pais { Id = item.Id, Nome = item.Nome, Ativo = "1" }; _entity.Entry(pais).State = !_entity.Pais.Any(f => f.Id == item.Id) ? EntityState.Added : EntityState.Modified; _entity.SaveChanges(); item.Id = pais.Id; } } catch (Exception e) { throw new ArgumentNullException(e.Message, Mensagem.HOUVEUMERRONAEXECUCAO.GetStringValue()); } return(item); }
public SensorValorModels Add(SensorValorModels item) { try { using (SensorEntities _entity = new SensorEntities()) { Sensor_valor sensorValor = new Sensor_valor { Id = item.Id, IdSensor = item.SensorModels.Id, TimesTamp = item.Timestamp, Valor = item.Valor, DataCadastrado = DateTime.Now }; _entity.Entry(sensorValor).State = !_entity.Sensor.Any(f => f.Id == item.Id) ? EntityState.Added : EntityState.Modified; _entity.SaveChanges(); } } catch (Exception e) { throw new ArgumentNullException(e.Message, Mensagem.HOUVEUMERRONAEXECUCAO.GetStringValue()); } return(item); }