public MainWindow() { InitializeComponent(); this.WindowState = WindowState.Maximized; //Initialisation Roles// Role admin = new Role() { Identifiant = "administrateur", Description = "Accès total à l'applicaton" }; Role limitedUser = new Role() { Identifiant = "utilisateur", Description = "Accès interdit au panneau utilisateur" }; listRoles.Add(admin); listRoles.Add(limitedUser); //Initialisation Users// Utilisateur ran = new Utilisateur("aa111bb", "Ranchon", "00000"); listUsers.Add(ran); listUsers.Add(new Utilisateur("bb0000bb", "Machin", "11111")); ran.Role = admin; Salarie tri = new Salarie("Ranchon", "Michel", "11aaa22"); tri.Poste = "Salarie"; listSalaries.Add(tri); }
public void CanAdd_should_throw_exception_if_name_exists() { var roles_1 = roles_0.Add(roleName); var command = new AddRole { Name = roleName }; ValidationAssert.Throws(() => GuardAppRoles.CanAdd(roles_1, command), new ValidationError("A role with the same name already exists.")); }
/// <summary> /// méthode d'initialisation /// </summary> private void InitApplication() { try { Utilisateurs listeUtil = new Utilisateurs(); Utilisateur u1 = new Utilisateur("A178APE", "loulou", "azerty") { CompteBloque = false }; Utilisateur u2 = new Utilisateur("B178APE", "Loulette", "azerty") { CompteBloque = false }; Role r1 = new Role() { Identifiant = "A178APE", Description = "Admin" }; Role r2 = new Role() { Identifiant = "B178APE", Description = "Utilisateur" }; Roles listRole = new Roles(); listRole.Add(r1); listRole.Add(r2); u1.Role = r1; u2.Role = r2; listeUtil.Add(u1); listeUtil.Add(u2); SauvegardeXML saveXml = new SauvegardeXML(); listeUtil.Save(saveXml, "Donnee"); listRole.Save(saveXml, "Donnee"); } catch (ApplicationException aE) { Debug.WriteLine(aE.Message); } catch (Exception e) { Debug.WriteLine(e.Message); } }
/// <summary> /// Adds a role to the Roles collection, ensuring that their /// aren't any duplicates. /// </summary> /// <param name="role">Role to be added to the collection.</param> private void AddRole(string role) { if (!Roles.Contains(role)) { Roles.Add(role); } }
public virtual void AssignRole(string role) { if (!HasRole(role)) { Roles.Add(role); } }
public IActionResult OnGet() { var initResult = Init(); if (initResult != null) { return(initResult); } InitPage(); if (UserRecord == null) { return(NotFound()); } UserName = (string)UserRecord["username"]; Email = (string)UserRecord["email"]; Image = (string)UserRecord["image"]; FirstName = (string)UserRecord["first_name"]; LastName = (string)UserRecord["last_name"]; Enabled = (bool)UserRecord["enabled"]; Verified = (bool)UserRecord["verified"]; foreach (var role in (List <EntityRecord>)UserRecord["$user_role"]) { Roles.Add(role["id"].ToString()); } BeforeRender(); return(Page()); }
private void SeedRoles() { var separtor = Path.DirectorySeparatorChar; var rolesFilePath = $"Config{separtor}Seeds{separtor}roles.json"; if (File.Exists(rolesFilePath)) { var rolesData = File.ReadAllText(rolesFilePath); var roles = JsonConvert.DeserializeObject <List <Role> >(rolesData); foreach (var item in roles) { var found = Roles.Find(item.Id); if (found != null) { found = found.Update(item); Roles.Update(found); } else { Roles.Add(item); } } SaveChanges(); } }
///<summary> /// Adds the role. /// </summary> /// <param name="role">The role.</param> public void AddRole(Role role) { if (Roles == null) { Roles = new List <Role>(); } // If there are not default role, set this one as default if (Roles.Where(x => x.IsDefault).Count() < 1) { role.IsDefault = true; } // If this is the new default role if (role.IsDefault) { foreach (Role rl in Roles) { rl.IsDefault = false; } } // If the role is not already in the list if (!Roles.Any(x => x.PrimaryKey == role.PrimaryKey)) { Roles.Add(role); } }
public void BuildNPCFromEmbed(Embed embed) { foreach (var aspectField in embed.Fields.Where(fld => fld.Name == StarforgedNPCResources.Aspect)) { Aspects.Add(aspectField.Value); } foreach (var dispositionField in embed.Fields.Where(fld => fld.Name == StarforgedNPCResources.Disposition)) { Dispositions.Add(dispositionField.Value); } foreach (var firstLook in embed.Fields.Where(fld => fld.Name == StarforgedNPCResources.FirstLook)) { FirstLooks.Add(firstLook.Value); } foreach (var goal in embed.Fields.Where(fld => fld.Name == NPCResources.Goal)) { Goals.Add(goal.Value); } foreach (var role in embed.Fields.Where(fld => fld.Name == NPCResources.Role)) { Roles.Add(role.Value); } Name = embed.Fields.FirstOrDefault(fld => fld.Name == NPCResources.Name).Value; IconUrl = embed.Thumbnail.HasValue ? embed.Thumbnail.Value.Url : null; EmbedDesc = embed.Description; }
private void SeedRoles() { Roles.Add(new IdentityRole(DefaultRoles.Administrator)); Roles.Add(new IdentityRole(DefaultRoles.User)); Roles.Add(new IdentityRole(DefaultRoles.PublicHealth)); SaveChanges(); }
// Enable initialization with an instance of ApplicationUser: public UserRolesViewModel(ApplicationUser user) : this() { UserName = user.UserName; FirstName = user.FirstName; LastName = user.LastName; var Db = new ApplicationDbContext(); var allRoles = Db.Roles;// Add all available roles to the list of EditorViewModels: foreach (var role in allRoles) { var rvm = new RoleEditorViewModel(role);// An EditorViewModel will be used by Editor Template: Roles.Add(rvm); } // Set the Selected property to true for those roles for which the current user is a member: foreach (var userRole in user.Roles) { string rn = userRole.RoleId; var checkUserRole = Roles.Find(r => r.RoleId == userRole.RoleId); if (checkUserRole != null) { checkUserRole.Selected = true; } } }
// Enable initialization with an instance of ApplicationUser: public UserPermissionsViewModel(ApplicationUser user) : this() { if (user != null) { this.UserName = user.UserName; this.FirstName = user.FirstName; this.LastName = user.LastName; IdentityManager Manager = new IdentityManager(); if (user.Roles != null) { if (user.Roles.Count < 1) { var RolesList = Manager.GetRolesForUser(user.Id); foreach (var Role in RolesList) { Roles.Add(new RoleViewModel(Role)); } } else { foreach (var role in user.Roles) { Roles.Add(new RoleViewModel(Manager.GetRole(role.RoleId))); } } } } }
/// <summary> /// Copies from model. /// </summary> /// <param name="model">The model.</param> public override void CopyFromModel(Data.IEntity model) { base.CopyFromModel(model); if (model is GroupType) { var groupType = (GroupType)model; this.IsSystem = groupType.IsSystem; this.Name = groupType.Name; this.Description = groupType.Description; this.GroupTerm = groupType.GroupTerm; this.GroupMemberTerm = groupType.GroupMemberTerm; this.DefaultGroupRoleId = groupType.DefaultGroupRoleId; this.AllowMultipleLocations = groupType.AllowMultipleLocations; this.ShowInGroupList = groupType.ShowInGroupList; this.ShowInNavigation = groupType.ShowInNavigation; this.IconCssClass = groupType.IconCssClass; this.TakesAttendance = groupType.TakesAttendance; this.AttendanceRule = groupType.AttendanceRule; this.AttendancePrintTo = groupType.AttendancePrintTo; this.Order = groupType.Order; this.InheritedGroupTypeId = groupType.InheritedGroupTypeId; this.LocationSelectionMode = groupType.LocationSelectionMode; this.GroupTypePurposeValueId = groupType.GroupTypePurposeValueId; this.locationTypeValueIDs = groupType.LocationTypes.Select(l => l.LocationTypeValueId).ToList(); this.Roles = new Dictionary <int, string>(); groupType.Roles.OrderBy(r => r.Order).ToList().ForEach(r => Roles.Add(r.Id, r.Name)); } }
private async Task LoadRoles(string userName) { try { LoginEnable = false; Roles.Clear(); RestStatus status = await RestHub.UserRoles(UserName); if (status.HttpCode == System.Net.HttpStatusCode.OK) { List <ProductRole> listRoles = (List <ProductRole>)status.UserObject; if (listRoles.Count > 0) { SelectIndex = 0; foreach (ProductRole productRole in listRoles) { Roles.Add(productRole); } LoginEnable = true; } } else { AppErrorBox.ShowErrorMessage("Can't Load Roles", status.StatusMessage); } } catch (Exception ex) { Log.This(ex); } }
public void agregarRole() { NewRole.Id = RoleQueries.CreateRole(NewRole.RoleName); System.Windows.MessageBox.Show("Nuevo Rol Creado."); Roles.Add(NewRole); limpiar(); }
/// <summary> /// Seeds the default data. /// </summary> private void Seed() { SaveChanges(); // Make sure we have a SysAdmin role var role = Roles.FirstOrDefault(r => r.Name == "SysAdmin"); if (role == null) { role = new Role { Id = Guid.NewGuid(), Name = "SysAdmin", NormalizedName = "SYSADMIN" }; Roles.Add(role); } // Make sure our SysAdmin role has all of the available claims //foreach (var claim in Piranha.Security.Permission.All()) foreach (var permission in App.Permissions.GetPermissions()) { var roleClaim = RoleClaims.FirstOrDefault(c => c.RoleId == role.Id && c.ClaimType == permission.Name && c.ClaimValue == permission.Name); if (roleClaim == null) { RoleClaims.Add(new IdentityRoleClaim <Guid> { RoleId = role.Id, ClaimType = permission.Name, ClaimValue = permission.Name }); } } SaveChanges(); }
// Enable initialization with an instance of ApplicationUser: public UserRolesViewModel(ApplicationUser user) : this() { UserName = user.UserName; FirstName = user.FirstName; LastName = user.LastName; var db = new ApplicationDbContext(); // Add all available roles to the list of EditorViewModels: var allRoles = db.Roles; var users = db.Users; foreach (var role in allRoles) { // An EditorViewModel will be used by Editor Template: var rvm = new RoleViewModel(role); Roles.Add(rvm); } // Set the Selected property to true for those roles for // which the current user is a member: foreach (var role in Roles) { foreach (var userRole in user.Roles) { if (userRole.RoleId == role.RoleId) { role.Selected = true; } } } }
/// <summary> /// Dodanie roli jaką pracownicy mogą przyjąć /// </summary> /// <param name="r">Nowa rola</param> public void AddRole(Role r) { if (!Roles.Exists(role => role.Name.Equals(r.Name))) { Roles.Add(r); } }
public void AddRole(Role oneRole) { if (!Roles.Contains(oneRole)) { Roles.Add(oneRole); } }
private async void OnAddRoleExecute() { if (!_rbacManager.LoggedUser.IsAdmin && !_rbacManager.LoggedUserHasPermission(AclVerbNames.UserConfiguration)) { await _messageDialogService.ShowAccessDeniedMessageAsync(this); return; } var dialogResult = await _messageDialogService .ShowInputMessageAsync(this, "Nowa rola", "Podaj nazwę dla nowej roli:"); if (!String.IsNullOrWhiteSpace(dialogResult)) { if (await _rbacManager.RoleExistsAsync(dialogResult)) { await _messageDialogService .ShowInformationMessageAsync(this, "Rola już istnieje...", "Rola o podanej nazwie już istnieje."); return; } else { var role = await _rbacManager.GetNewRole(dialogResult); _rbacManager.AddRole(role); Roles.Add(role); } } }
private void EnsureRole(RoleInfo role) { if (Roles.Cast <RoleInfo>().All(r => r.RoleID != role.RoleID)) { Roles.Add(role); } }
private void GetRoles() { int roleGroupId = -2; if ((cboRoleGroups != null) && (cboRoleGroups.SelectedValue != null)) { roleGroupId = int.Parse(cboRoleGroups.SelectedValue); } if (roleGroupId > -2) { Roles = new ArrayList(TestableRoleController.Instance.GetRoles(PortalController.GetCurrentPortalSettings().PortalId, r => r.RoleGroupID == roleGroupId && r.SecurityMode != SecurityMode.SocialGroup && r.Status == RoleStatus.Approved).ToArray()); } else { Roles = new ArrayList(TestableRoleController.Instance.GetRoles(PortalController.GetCurrentPortalSettings().PortalId, r => r.SecurityMode != SecurityMode.SocialGroup && r.Status == RoleStatus.Approved).ToArray()); } if (roleGroupId < 0) { Roles.Add(new RoleInfo { RoleID = int.Parse(Globals.glbRoleUnauthUser), RoleName = Globals.glbRoleUnauthUserName }); Roles.Add(new RoleInfo { RoleID = int.Parse(Globals.glbRoleAllUsers), RoleName = Globals.glbRoleAllUsersName }); } Roles.Reverse(); Roles.Sort(new RoleComparer()); }
public void AddToRole(string roleName) { Roles.Add(new IdentityUserRole() { RoleId = roleName, UserId = this.Id }); }
// Enable initialization with an instance of ApplicationUser: public SelectUserRolesViewModel(Employee user) : this() { UserName = user.UserName; var db = new HrisDbContext(); // Add all available roles to the list of EditorViewModels: var allRoles = db.Roles; foreach (var role in allRoles) { var rvm = new SelectRoleEditorViewModel(role); Roles.Add(rvm); } // Set the Selected property to true for those roles for // which the current user is a member: foreach (var userRole in user.Roles) { var checkUserRole = Roles.Find(r => r.RoleId == userRole.RoleId); checkUserRole.Selected = true; } }
public void AddRole(ConventionRoles role) { if (Roles.Missing(role)) { Roles.Add(role); } }
private void Layout() { InteractionGraph = new BidirectionalGraph <RoleViewModel, IEdge <RoleViewModel> >(); for (int zindex = Model.Roles.Values.Count - 1; zindex >= 0; --zindex) { var r = Model.Roles.Values.ElementAt(zindex); var roleViewModel = new RoleViewModel(r); Roles.Add(roleViewModel); roleViewModel.ZIndex = zindex; SelectedItem = SelectedItem == null ? roleViewModel : SelectedItem; _Graph.AddVertex(roleViewModel); } foreach (var interaction in Model.Interactions) { var source = Roles.FirstOrDefault(r => r.Model == interaction.Source); var target = Roles.FirstOrDefault(r => r.Model == interaction.Target); _Graph.AddEdge(new Edge <RoleViewModel>(source, target)); } }
// Enable initialization with an instance of ApplicationUser: public RoleService(ApplicationUser user) : this() { UserName = user.UserName; FirstName = user.FirstName; LastName = user.LastName; var Db = new FClubBarcelonaContext(); var allRoles = Db.Roles; foreach (var role in allRoles) { // An EditorViewModel will be used by Editor Template: var rvm = new SelectRoleEditorViewModel(role); Roles.Add(rvm); } // Set the Selected property to true for those roles for // which the current user is a member: foreach (var userRole in user.Roles) { var checkUserRole = Roles.Find(r => r.Id == userRole.RoleId); checkUserRole.Selected = true; } }
public void CreateDefaultAccount(IPasswordService passwordService) { if (Users.Any(u => u.Login == "administrator")) { return; } // create admin role var adminRole = new Role() { Name = "admin" }; Roles.Add(adminRole); // create admin user var salt = string.Empty; var hash = passwordService.HashPassword("password", out salt); var adminUser = new User() { Login = "******", PasswordHash = hash, HashSalt = salt }; // link user and role UserRoles.Add(new UserRole { Role = adminRole, User = adminUser }); SaveChanges(); }
public void BuildNPCFromEmbed(Embed embed) { foreach (var activityField in embed.Fields.Where(fld => fld.Name == NPCResources.Activity)) { Activities.Add(activityField.Value); } foreach (var dispositionField in embed.Fields.Where(fld => fld.Name == NPCResources.Disposition)) { Dispositions.Add(dispositionField.Value); } foreach (var goal in embed.Fields.Where(fld => fld.Name == NPCResources.Goal)) { Goals.Add(goal.Value); } foreach (var role in embed.Fields.Where(fld => fld.Name == NPCResources.Role)) { Roles.Add(role.Value); } foreach (var desc in embed.Fields.Where(fld => fld.Name == NPCResources.Descriptor)) { Descriptors.Add(desc.Value); } Name = embed.Fields.FirstOrDefault(fld => fld.Name == NPCResources.Name).Value; IconUrl = embed.Thumbnail.HasValue ? embed.Thumbnail.Value.Url : null; EmbedDesc = embed.Description; }
public async void CreateDefaultAccount() { if (!Users.Any(u => u.Login == "administrator")) { // create admin role var adminRole = new Role() { Name = "admin" }; Roles.Add(adminRole); // create admin user var salt = string.Empty; var hash = AuthHelper.HashPassword("password", out salt); var adminUser = new User() { Login = "******", PasswordHash = hash, HashSalt = salt }; // link user and role UserRoles.Add(new UserRole { Role = adminRole, User = adminUser }); await SaveChangesAsync(); } }