예제 #1
0
        public async Task <IActionResult> PutMeterTbl([FromRoute] string id, [FromBody] MeterTbl meterTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != meterTbl.MeterId)
            {
                return(BadRequest());
            }

            _context().Entry(meterTbl).State = EntityState.Modified;

            try
            {
                await _context().SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MeterTblExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PostMeterTbl([FromBody] MeterTbl meterTbl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context().MeterTbl.Add(meterTbl);
            try
            {
                await _context().SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (MeterTblExists(meterTbl.MeterId))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetMeterTbl", new { id = meterTbl.MeterId }, meterTbl));
        }
예제 #3
0
        private void MeterChanged(object sender, RecordChangedEventArgs <MeterTbl> e)
        {
            if (e.ChangeType != ChangeType.None)
            {
                MeterTbl meterData = new MeterTbl();

                meterData.MeterId       = e.Entity.MeterId;
                meterData.timestamp     = e.Entity.timestamp;
                meterData.RMS_Watts_Tot = e.Entity.RMS_Watts_Tot;

                _hubContext.Clients.All.SendAsync("ReceiveMeterKWData", meterData);
            }
        }