Пример #1
0
        public void Test_UserRoleExtension_GetCheckBoxClass()
        {
            var value = new UserRoleRelationUpdate
            {
                Role = new UserRole()
            };

            var value2 = new UserRoleRelationUpdateValue();

            Assert.AreEqual(
                "checkbox",
                value.GetCheckBoxClass(value2),
                "Not Selected"
            );

            value2.Selected = true;

            Assert.AreEqual(
                "checkbox checkbox-selected",
                value.GetCheckBoxClass(value2),
                "Selected"
            );

            value.Role.IsAdministrator = true;
            value2.Selected = false;

            Assert.AreEqual(
                "checkbox checkbox-administrator",
                value.GetCheckBoxClass(value2),
                "Administrator Not Selected"
            );

            value2.Selected = true;

            Assert.AreEqual(
                "checkbox checkbox-administrator checkbox-administrator-selected",
                value.GetCheckBoxClass(value2),
                "Administrator Selected"
            );
        }
Пример #2
0
        public void Test_UserRoleExtension_GetTitleClass()
        {
            var value = new UserRoleRelationUpdate
            {
                Role = new UserRole()
            };

            Assert.AreEqual(
                "role",
                value.GetTitleClass(),
                "Not Selected"
            );

            value.Selected = true;

            Assert.AreEqual(
                "role role-selected",
                value.GetTitleClass(),
                "Selected"
            );

            value.Selected = false;
            value.Role.IsAdministrator = true;

            Assert.AreEqual(
                "role role-administrator",
                value.GetTitleClass(),
                "Administrator Not Selected"
            );

            value.Selected = true;

            Assert.AreEqual(
                "role role-administrator role-administrator-selected",
                value.GetTitleClass(),
                "Administrator Selected"
            );
        }
Пример #3
0
        /// <summary>
        /// Initializes the specified user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="roles">The roles.</param>
        /// <param name="privileges">The privileges.</param>
        public void Initialize(User user, IEnumerable<UserRole> roles, IEnumerable<UserRoleRelation> privileges)
        {
            this.UserId = user.Id;
            this.User = user;
            this.Names = Enum.GetNames(typeof(Privileges));
            this.Values = new List<UserRoleRelationUpdate>();

            var dictionary = privileges.ToDictionary(x => x.Role.Title);
            var values = Enum.GetValues(typeof(Privileges)) as int[];

            if (values == null)
            {
                return;
            }

            foreach (var role in roles)
            {
                var relation = new UserRoleRelationUpdate
                {
                    RoleId = role.Id,
                    Selected = dictionary.ContainsKey(role.Title),
                    Role = role,
                    Privileges = new List<UserRoleRelationUpdateValue>()
                };

                foreach (var privilege in values)
                {
                    relation.Privileges.Add(
                        new UserRoleRelationUpdateValue
                        {
                            Privilege = privilege,
                            Selected = dictionary.Has(role.Title, privilege)
                        }
                    );
                }

                this.Values.Add(relation);
            }
        }