forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountService.cs
More file actions
56 lines (47 loc) · 1.78 KB
/
Copy pathAccountService.cs
File metadata and controls
56 lines (47 loc) · 1.78 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
51
52
53
54
55
56
using System.Linq;
using System.Threading.Tasks;
using L2dotNET.DataContracts;
using L2dotNET.Repositories.Abstract;
using L2dotNET.Repositories.Contracts;
using L2dotNET.Services.Contracts;
using L2dotNET.Utility;
namespace L2dotNET.Services
{
public class AccountService : IAccountService
{
private readonly IAccountRepository _accountRepository;
private readonly ICrudRepository<AccountContract> _accountCrudRepository;
public AccountService(IAccountRepository accountRepository, ICrudRepository<AccountContract> accountCrudRepository)
{
_accountRepository = accountRepository;
_accountCrudRepository = accountCrudRepository;
}
public async Task<AccountContract> GetAccountByLogin(string login)
{
return await _accountRepository.GetAccountByLogin(login);
}
public async Task<AccountContract> CreateAccount(string login, string password)
{
AccountContract acc = new AccountContract
{
Login = login,
Password = L2Security.HashPassword(password)
};
acc.AccountId = (int)await _accountCrudRepository.Add(acc);
return acc;
}
public async Task<bool> CheckIfAccountIsCorrect(string login, string password)
{
AccountContract account = await GetAccountByLogin(login);
return account != null && account.Password.SequenceEqual(L2Security.HashPassword(password));
}
public void UpdateAccount(AccountContract account)
{
_accountCrudRepository.Update(account);
}
public void DeleteAccount(AccountContract account)
{
_accountCrudRepository.Delete(account);
}
}
}