示例#1
0
        // POST api/values
        public void Post([FromBody] DeviceDataEntry value)
        {
            var entry = new DeviceEntry
            {
                id                = Guid.NewGuid(),
                dataType          = value.DataType,
                value             = value.Value,
                direction         = value.Direction,
                sourceDescription = value.SourceDescription,
                sourceId          = value.SourceId,
                timestamp         = DateTime.Now
            };

            Context.DeviceEntries.Add(entry);
            Context.SaveChanges();
        }
示例#2
0
        // PUT api/values/5
        public void Put(Guid id, [FromBody] DeviceDataEntry value)
        {
            var item = Context.DeviceEntries.Find(id);

            if (item != null)
            {
                item.value             = value.Value;
                item.dataType          = value.DataType;
                item.direction         = value.Direction;
                item.sourceId          = value.SourceId;
                item.sourceDescription = value.SourceDescription;
                item.timestamp         = DateTime.Now;

                Context.DeviceEntries.AddOrUpdate(item);
                Context.SaveChanges();
            }
        }