Guest User

Untitled

a guest
Jan 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public class LoginModel
  2. {
  3. public string Email { get; set; }
  4. public string Senha { get; set; }
  5.  
  6. public bool ValidarLogin()
  7. {
  8. // Comando para fazer a consulta
  9. string consultaSql = $"Select VendedorId From Estudo.Vendedores Where Email='{Email}' and Senha='{Senha}'";
  10. DAL Acessar = new DAL();
  11. DataTable carregaTabela = new DataTable(consultaSql); // Comando para executar a consulta.
  12.  
  13. if (carregaTabela.Rows.Count == 1)
  14. {
  15. return true;
  16. }
  17. else
  18. {
  19. return false;
  20. }
  21. }
  22. }
  23.  
  24. public class DAL
  25. {
  26. // Variaveis de conexão
  27. private static string NomeServidor = @"DESKTOP-DC0D3FTTHIAGO";
  28. private static string TipoAutenticacao = "SSPI";
  29. private static string NomeBanco = "SistemaDeVenda";
  30. private static string StringConexao = $"Data source={NomeServidor}; Integrated Security={TipoAutenticacao}; Initial Catalog={NomeBanco}" ;
  31. private static SqlConnection Conexao;
  32.  
  33.  
  34. //@"data source=DESKTOP-DC0D3FTTHIAGO; Integrated Security=SSPI;Initial Catalog=SistemaDeVenda"
  35.  
  36. public DAL()
  37.  
  38. {
  39. Conexao = new SqlConnection(StringConexao);
  40. Conexao.Open();
  41. }
  42.  
  43. public DataTable RetDataTable(string sql)
  44. {
  45. DataTable data = new DataTable();
  46. SqlCommand Executar = new SqlCommand(sql, Conexao);
  47. SqlDataAdapter da = new SqlDataAdapter(Executar);
  48. da.Fill(data);
  49. return data;
  50. }
  51.  
  52. public void ExecutarComandoSQL(string sql)
  53. {
  54. SqlCommand Executar = new SqlCommand(sql, Conexao );
  55. Executar.ExecuteNonQuery();
  56. }
  57.  
  58.  
  59. }
  60.  
  61. [HttpPost]
  62. public IActionResult Login(LoginModel login)
  63. {
  64. bool loginOk = login.ValidarLogin();
  65. return View();
  66. }
Add Comment
Please, Sign In to add comment