-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repositories.cs
39 lines (33 loc) · 1.05 KB
/
Repositories.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Data.SQLite;
using authenticator.Models;
namespace authenticator.Repositories
{
public class UserRepository
{
private SQLiteConnection conn;
public UserRepository(SQLiteConnection connection)
{
conn = connection;
}
public User? GetByEmail(string email)
{
string queryString = "SELECT * FROM users WHERE email like @email";
using (SQLiteCommand cmd = new SQLiteCommand(queryString, conn))
{
cmd.Parameters.AddWithValue("@email", email);
SQLiteDataReader rdr = cmd.ExecuteReader();
if(rdr.Read())
{
User user = new User(
userId: (long)rdr["id"],
name: rdr["name"].ToString()!,
email: rdr["email"].ToString()!,
password: rdr["password"].ToString()!
);
return user;
}
}
return null;
}
}
}