private void CerrarSesion()
        {
            VistaLogin vistaLogin = new VistaLogin();

            vistaLogin.Show();
            this.Close();
        }
        public async Task <Response> Login([FromBody] VistaLogin vista)
        {
            try
            {
                Usuarios user = null;


                user = await db.Set <Usuarios>().Where(u => u.Codigo.ToLower() == vista.Codigo.ToLower()).FirstOrDefaultAsync();



                if (user == null)
                {
                    return(new Response {
                        IsSuccess = false, Message = "Este usuario no existe.", Result = null
                    });
                }

                user = ToVistaUsuario(user);

                if (!(vista.Contrasena == user.Contrasena))
                {
                    return(new Response {
                        IsSuccess = false, Message = "ContraseƱa incorrecta", Result = null
                    });
                }

                if (!user.Activo)
                {
                    return(new Response {
                        IsSuccess = false, Message = "Usuario inactivo", Result = null
                    });
                }
                user.Contrasena = "";

                return(new Response {
                    IsSuccess = true, Message = string.Empty, Result = user
                });
            }
            catch (Exception ex)
            {
                return(new Response {
                    IsSuccess = false, Message = ex.Message, Result = null
                });
            }
        }