public async Task<IdentityResult> RegisterUser(User user, string password) { user.IsActive = true; user.UpdatedAt = DateTime.UtcNow; user.Id = Guid.NewGuid().ToString(); var result = await _userManager.CreateAsync(user, password); await _userManager.AddToRoleAsync(user.Id, user.AccountType); return result; }
public static List<Account> GetAccounts(User client) { BankContext bank = new BankContext(); List<Account> accounts = new List<Account>(); foreach (var item in bank.Accounts.ToList()) { if (item.ClientId.ToString().Equals(client.Id)) { accounts.Add(item); } } return accounts; }
public static void CreateAccount(User client, Currency currency) { BankContext bank = new BankContext(); Account account = new Account(); account.ClientId = client.Id; account.OpeningDate = DateTime.UtcNow; account.Currency = currency; account.Amount = 0; bank.Accounts.Add(account); bank.SaveChanges(); }
public async Task<IdentityResult> CreateAsync(User user) { var result = await _userManager.CreateAsync(user); return result; }
public IdentityResult UpdateUser(User user) { user.UpdatedAt = DateTime.UtcNow; var result = _userManager.Update(user); if (!string.IsNullOrEmpty(user.AccountType) && _userManager.IsInRole(user.Id, user.AccountType)) { _userManager.RemoveFromRoles(user.Id); _userManager.AddToRole(user.Id, user.AccountType); } return result; }
public static AuthenticationProperties CreateProperties(User user) { IDictionary<string, string> data = new Dictionary<string, string> { { "user_id", user.Id }, { "isClient", user.IsRegularUser.ToString() }, { "firstName", user.FirstName }, { "lastName", user.LastName }, }; return new AuthenticationProperties(data); }