-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathUserAccountService.cs
More file actions
50 lines (45 loc) · 1.37 KB
/
UserAccountService.cs
File metadata and controls
50 lines (45 loc) · 1.37 KB
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
40
41
42
43
44
45
46
47
48
49
50
/*
namespace BlazorServerAuthenticationAndAuthorization.Authentication
{
public class UserAccountService
{
private List<UserAccount> _users;
public UserAccountService()
{
_users = new List<UserAccount>
{
new UserAccount{ UserName = "admin", Password = "admin", Role = "Administrator" },
new UserAccount{ UserName = "user", Password = "user", Role = "User" }
};
}
public UserAccount? GetByUserName(string userName)
{
return _users.FirstOrDefault(x => x.UserName == userName);
}
}
}
*/
using BlazorAppProjekt.Data;
using BlazorAppProjekt.Models;
using System.Collections.Generic;
using System.Linq;
namespace BlazorServerAuthenticationAndAuthorization.Authentication
{
public class UserAccountService
{
private readonly MyDbContext _dbContext;
public UserAccountService(MyDbContext dbContext)
{
_dbContext = dbContext;
}
public UserAccount? GetByUserName(string userName)
{
var user = _dbContext.Users.FirstOrDefault(x => x.UserName == userName);
if (user == null)
{
return null;
}
return new UserAccount { UserName = user.UserName, Password = user.Password, Role = user.userlevel };
}
}
}