Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        protected async Task FormSubmit(PowerMeterInstantaneous args)
        {
            try
            {
                await IoTSuiteService.UpdatePowerMeter(args);

                DialogService.Close(args);
            }
            catch
            {
                NotificationService.Notify(NotificationSeverity.Error, $"Error", $"Unable to update PowerMeter");
            }
        }
Ejemplo n.º 3
0
 protected override async Task OnInitializedAsync()
 {
     powerMeterInstantaneous = (await IoTSuiteService.GetPowerMeter(Id)).Data;
 }
Ejemplo n.º 4
0
 public async Task Notification(PowerMeterInstantaneous powerMeterInstantaneous)
 {
     await _hubContext.Clients.All.SendAsync("PowerMeterInstantaneousNotification", powerMeterInstantaneous);
 }
Ejemplo n.º 5
0
 public async Task UpdatePowerMeter(PowerMeterInstantaneous powerMeterInstantaneous)
 {
     await httpClient.PutAsJsonAsync($"PowerMeter/Instantaneous/{powerMeterInstantaneous.Id}", powerMeterInstantaneous, jsonSerializerOptions);
 }