public void CreateAccountWithExistingRoleTest() { const string roleName = "testRole"; const string userName = "******"; ISecurityRepository client = GetClient(); var role = new Role() { Name = roleName }; client.Add(role); client.UnitOfWork.Commit(); EndActionClearRole(roleName); string roleId = role.RoleId; client = GetClient(); role = client.Roles.Where(x => x.RoleId == roleId).FirstOrDefault(); client.Attach(role); var account = new Account() { UserName = userName }; var roleAssignment = new RoleAssignment { Account = account, AccountId = account.AccountId, Role = role, RoleId = role.RoleId }; // add role to account account.RoleAssignments.Add(roleAssignment); client.Add(account); client.UnitOfWork.Commit(); string accountId = account.AccountId; EndActionClearAccount(userName); client = GetClient(); int count = client.Accounts.Where(x => x.AccountId == accountId).Count(); Assert.Equal(count, 1); count = client.Roles.Where(x => x.RoleId == roleId).Count(); Assert.Equal(count, 1); count = client.RoleAssignments.Where(x => x.RoleId == roleId && x.AccountId == accountId).Count(); Assert.Equal(count, 1); }
public void CreateUserRole(UserRole userRole) { if (userRole == null) { throw new ArgumentNullException("The user role object must not be null"); } userRoleRepository.Add(userRole); securityUnitOfWork.Commit(); }
public void CreateWebsitePermission(WebSiteAccessPermission webSiteAccessPermission) { if (webSiteAccessPermission == null) { throw new ArgumentNullException("The web site access permission object must not be null"); } webSiteAccessPermissionRepository.Add(webSiteAccessPermission); securityUnitOfWork.Commit(); }
public async Task <string> CreateUserAndAccountAsync(string userName, string password, object propertyValues = null, bool requireConfirmationToken = false) { var account = _securityRepository.Accounts.FirstOrDefault(x => x.UserName.Equals(userName, StringComparison.OrdinalIgnoreCase)); if (account != null) { throw new InvalidOperationException(string.Format("username {0} already taken", userName)); } var user = new ApplicationUser { UserName = userName, Email = userName, }; var result = await UserManager.CreateAsync(user, password); if (result.Succeeded) { IDictionary <string, object> values = propertyValues as RouteValueDictionary; if (values == null && propertyValues != null) { var propertyValuesAsDictionary = propertyValues as IDictionary <string, object>; values = propertyValuesAsDictionary != null ? new RouteValueDictionary(propertyValuesAsDictionary) : new RouteValueDictionary(propertyValues); } account = new Account { UserName = userName, AccountId = user.Id }; if (values != null) { foreach (var prop in account.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(prop => values.ContainsKey(prop.Name))) { prop.SetValue(account, values[prop.Name]); } } _securityRepository.Add(account); _securityRepository.UnitOfWork.Commit(); if (requireConfirmationToken) { return(await UserManager.GenerateEmailConfirmationTokenAsync(user.Id)); } } return(null); }
private void CreateRole(string name, IEnumerable <Permission> allPermissions, ICollection <string> permissionList, ISecurityRepository client) { var item = new Role { Name = name }; var rolePermissions = allPermissions.Where(x => permissionList.Contains(x.PermissionId)).ToList(); rolePermissions.ForEach(x => item.RolePermissions.Add(new RolePermission { PermissionId = x.PermissionId, RoleId = item.RoleId })); client.Add(item); }
public void CreateRole(Role role) { if (role == null) { throw new ArgumentNullException("The role object must not be null"); } if (string.IsNullOrEmpty(role.Name)) { throw new ArgumentNullException("The role name must not be null or empty"); } role.Id = Guid.NewGuid(); roleRepository.Add(role); securityUnitOfWork.Commit(); }
public void CreateUser(User user) { if (user == null) { throw new ArgumentNullException("user cannot be null"); } if (string.IsNullOrEmpty(user.ADName)) { throw new ArgumentNullException("user must have a valid ADName"); } user.Id = Guid.NewGuid(); userRepository.Add(user); securityUnitOfWork.Commit(); }
public async Task <IActionResult> CreateSecurity([FromBody] SecurityResource securityResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var security = Mapper.Map <SecurityResource, Security>(securityResource); _securityRepository.Add(security); await _uow.CompleteAsync(); security = await _securityRepository.GetSecurity(security.Id); var result = _mapper.Map <Security, SecurityResource>(security); return(Ok(result)); }
/// <summary> /// Creates the account. /// </summary> /// <param name="account">The account.</param> public virtual void CreateAccount(Account account) { _securityRepository.Add(account); SaveSecurityChanges(); }