public async Task <IActionResult> Putiot_task(long id, iot_task iot_task) { if (id != iot_task.id) { return(BadRequest()); } _context.Entry(iot_task).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!iot_taskExists(id)) { return(NotFound()); } else { throw; } } var lMsg = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.UPDATE, id); var lJson = JsonConvert.SerializeObject(lMsg); await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson); return(NoContent()); }
public async Task <ActionResult <iot_task> > Postiot_task(iot_task iot_task) { _context.iot_task.Add(iot_task); await _context.SaveChangesAsync(); var lMsg = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.INSERT, iot_task.id); var lJson = JsonConvert.SerializeObject(lMsg); await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson); return(CreatedAtAction("Getiot_task", new { id = iot_task.id }, iot_task)); }
public async Task <IActionResult> Putiot_task_failed(long id, iot_task iot_task) { if (id != iot_task.id) { return(BadRequest()); } _context.Entry(iot_task).State = EntityState.Modified; try { if (iot_task.completed.HasValue) { await _context.Database.ExecuteSqlRawAsync( "UPDATE iot_task SET " + " completed={1}, " + " taskstatusnm='FAILED' " + " WHERE id={0}", parameters : new[] { iot_task.id.ToString(), iot_task.completed.ToString() }); } else { await _context.Database.ExecuteSqlRawAsync( "UPDATE iot_task SET " + " completed=null, " + " taskstatusnm='FAILED' " + " WHERE id={0}", parameters : iot_task.id); } } catch (DbUpdateConcurrencyException) { if (!iot_taskExists(id)) { return(NotFound()); } else { throw; } } var lMsg = new ServerUpdateHubMsg(_entity, ServerUpdateHubMsg.TOperation.UPDATE, id); var lJson = JsonConvert.SerializeObject(lMsg); await _hubContext.Clients.All.SendAsync(lMsg.entity, lJson); return(NoContent()); }