Ejemplo n.º 1
0
        public IActionResult Update(Guid id, [FromBody] dynamic body)//[FromBody]Apoiado conexaoNew)
        {
            if (string.IsNullOrEmpty(body.ToString()))
            {
                return(BadRequest());
            }

            //Verifica se o registro existe na base
            var conexaoFounded = _conexaoRepository.Find(id);

            if (conexaoFounded == null)
            {
                return(NotFound());
            }

            Conexao conexaoNew = new Conexao();

            conexaoNew = conexaoFounded;
            conexaoNew.DeserializeJson(body); //Converte Json para o objeto Apoiado
            conexaoNew.SetDataAlteracao();

            //Verifica se há inconsistência nos dados
            ConexaoAssertion conexaoAssertion = new ConexaoAssertion(conexaoNew);

            if (conexaoAssertion.Notifications.HasNotifications())
            {
                Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError;
                return(new ObjectResult(conexaoAssertion.Notifications.Notify()));
            }
            _conexaoRepository.Update(conexaoNew);
            //return new NoContentResult();
            Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status200OK;
            return(new ObjectResult(conexaoNew));
        }
Ejemplo n.º 2
0
        /*public override async Task OnConnectedAsync()
         * {
         *  //await Clients.Client(Context.ConnectionId).InvokeAsync("SetUsersOnline", await GetUsersOnline());
         *
         *  await base.OnConnectedAsync();
         * }*/

        public async Task GetStatusDB(Guid id)
        {
            Models.Conexao conexao = _userRepository.Find(id);
            if (conexao != null)
            {
                TestConnectionAssertion testConnectionAssertion = new TestConnectionAssertion(
                    conexao.Ip, conexao.Porta, conexao.NomeServidor,
                    conexao.Usuario, conexao.Senha
                    );
                if (!testConnectionAssertion.Notifications.HasNotifications())
                {
                    string connectionString = Utils.Connection.GetConnectionString(conexao);
                    string status           = Utils.Connection.TestConnection(connectionString, _configuration["UrlStatusDb"]);

                    conexao.DataStatus = DateTime.Now;
                    conexao.Status     = status;

                    _userRepository.Update(conexao);
                    await Clients.All.InvokeAsync("StatusDBResponse", conexao.Id, conexao.Status, conexao.DataStatus.ToString());
                }
            }
        }