public async Task Handle() { try { var waterMeterDto = GetInputModel(); var result = await _waterMeterBusiness.Add(waterMeterDto); 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> RegisterWaterMeter(WaterMeterViewModel 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 _waterMeterBusiness.Add(new WaterMeterDto { SerialNumber = model.SerialNumber, FirmwareVersion = model.FirmwareVersion, State = model.State }); response .SetStatus(insertResult.Success) .SetMessage(insertResult.Message) .SetData(insertResult.Data); return(Json(response)); }