コード例 #1
0
        public async Task <IActionResult> Post([FromBody] Alarm alarm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var alarmCurrent = await _alarmService.AddAlarm(alarm);

                    if (alarmCurrent == null)
                    {
                        return(StatusCode(500, "Erro processo de inserção no banco"));
                    }

                    return(Created($"api/alarm/{alarmCurrent.thingId}", alarmCurrent));
                }

                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }