public async Task <IActionResult> PutPowerMeterInstantaneous(long Id, PowerMeterInstantaneousDTO powerMeterInstantaneousDTO) { var powerMeterInstantaneous = await _context.PowerMeterInstantaneous.FindAsync(Id); if (powerMeterInstantaneous == null) { return(NotFound()); } powerMeterInstantaneous.MapFromDTO(powerMeterInstantaneousDTO); _context.Entry(powerMeterInstantaneous).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(NoContent()); }
public async Task <ActionResult <Response <PowerMeterInstantaneous> > > PostPowerMeterInstantaneous(PowerMeterInstantaneousDTO powerMeterInstantaneousDTO) { var thing = _context.Thing.AsNoTracking().Where(thing => thing.ThingId.Equals(powerMeterInstantaneousDTO.ThingId)).FirstOrDefault(); string message = string.Empty; if (thing == null) { message = $"Thing with Id {powerMeterInstantaneousDTO.ThingId} not found"; } if (message != string.Empty) { Debug.WriteLine(message); return(BadRequest(new Response <Exception>( HttpStatusCode.BadRequest, message ))); } PowerMeterInstantaneous powerMeterInstantaneous = new PowerMeterInstantaneous(powerMeterInstantaneousDTO); _context.PowerMeterInstantaneous.Add(powerMeterInstantaneous); await _context.SaveChangesAsync(); await Notification(powerMeterInstantaneous); return(CreatedAtAction("GetPowerMeterInstantaneous", new { id = powerMeterInstantaneous.Id }, powerMeterInstantaneous)); }