public async Task Handle() { try { var electricMeterDto = GetInputModel(); var result = await _electricMeterBusiness.Add(electricMeterDto); if (result.Success) { Console.WriteLine("{0}\n", result.Message); Console.WriteLine("\tId: {0}\n\tSerial number: {1}", result.Data.Id, result.Data.SerialNumber); Console.WriteLine("\tFirmware Version: {0}\n\tState: {1}", result.Data.FirmwareVersion, result.Data.State); } else { Console.WriteLine("Error: {0}", result.Message); } } catch (Exception ex) { _logger.LogError(ex.Message); } Console.Write("\n> "); }
public async Task <IActionResult> RegisterElectricMeter(ElectricMeterViewModel model) { var response = new ApiResponseModel(); if (!ModelState.IsValid) { response.SetMessage("INVALID_INPUT").SetData(ModelState.Values.SelectMany(v => v.Errors)); return(Json(response)); } var insertResult = await _electricMeterBusiness.Add(new ElectricMeterDto { SerialNumber = model.SerialNumber, FirmwareVersion = model.FirmwareVersion, State = model.State }); response .SetStatus(insertResult.Success) .SetMessage(insertResult.Message) .SetData(insertResult.Data); return(Json(response)); }