Ejemplo n.º 1
0
        public static async Task<Sensor> Insert(Sensor data)
        {
            var ctx = ModelContext.GetInstance();

            ctx.sensors.Add(toRaw(data));

            await ctx.SaveChangesAsync();
            return (Sensor)ctx.sensors.OrderByDescending(x => x.id).FirstOrDefault();
        }
Ejemplo n.º 2
0
        public static async Task<Sensor> Update(Sensor data)
        {
            var ctx = ModelContext.GetNewInstance();

            var raw = toRaw(data);
            ctx.sensors.Attach(raw);
            System.Data.Entity.Infrastructure.DbEntityEntry<Database.sensor> entry = ctx.Entry(raw);
            entry.State = System.Data.Entity.EntityState.Modified;

            await ctx.SaveChangesAsync();

            return Get((int)data.Id);
        }
Ejemplo n.º 3
0
        public static Database.sensor toRaw(Sensor data)
        {
            var raw = new Database.sensor()
            {
                sensor_type = data.SensorType,
                friendly_name = data.FriendlyName,
                measurement_name = data.MeasurementName,
                measurement_unit = data.MeasurementUnit,
                node_id = data.NodeId,
            };

            if (data.Id != null)
            {
                raw.id = (int)data.Id;
            }

            return raw;
        }