コード例 #1
0
ファイル: IMRoleRepository.cs プロジェクト: cigno/ReSolution
        public void SaveRole(RoleSet roleSet)
        {
            if (roleSet.RoleSetId == 0)
            {
                RoleSet lastRoleSet = roleSets.Last<RoleSet>();
                int id = lastRoleSet.RoleSetId + 1;

                roleSet.RoleSetId = id;

                roleSets.Add(roleSet);
            }
            else
            {
                RoleSet roleSetToRemove = roleSets.FirstOrDefault(r => r.RoleSetId == roleSet.RoleSetId);
                roleSets.Remove(roleSetToRemove);
                roleSets.Add(roleSetToRemove);
            }
        }
コード例 #2
0
ファイル: RoleController.cs プロジェクト: cigno/ReSolution
        public ActionResult Create(string roleName)
        {
            // Creates a new Role Set with the provided roleName
            // And assign a set of default rules taken from the
            // "Users Role Set"

            RoleSet userRoleSetTemplate = repository.RoleSets.FirstOrDefault(r => r.RoleSetId == 3); // Users RoleSet

            RoleSet roleSet = new RoleSet();
            roleSet.Name = roleName;
            roleSet.Roles = new List<RoleSetting>();

            foreach (RoleSetting roleSetting in userRoleSetTemplate.Roles)
            {
                roleSet.Roles.Add(new RoleSetting() {
                    Role = roleSetting.Role,
                    IsActive = roleSetting.IsActive
                });
            }

            try
            {
                repository.SaveRole(roleSet);
                TempData["message"] = new Alert()
                {
                    Class = "Success",
                    Title = "Role added.",
                    Description = roleName + " has been added"
                };

                return RedirectToAction("Settings", new { id = roleSet.RoleSetId });
            }
            catch (Exception e)
            {
                TempData["message"] = new Alert(e);
                return RedirectToAction("Index");
            }
        }
コード例 #3
0
ファイル: Seeder.cs プロジェクト: cigno/ReSolution
        public static void SeedData()
        {
            RSDbContext context = new RSDbContext();

            Member member;
            Role[] roles;

            if (context.Members.Count() == 0)
            {
                member = new Member
                {
                    MemberGuid = Guid.NewGuid(),
                    UserName = "root",
                    Email = "[email protected]",
                    Profile = new Profile
                    {
                        FirstName = "Admin",
                        LastName = "Root",
                        Description = "Application Administrator",
                        Phone = "",
                        Address = "",
                        Building = "",
                        Floor = "",
                        Office = ""
                    },
                    Password = new Password
                    {
                        Hash = "BB595D807F9615796C9B99A52CE4E8F07347C899",
                        Salt = "sVGQGTu+CZH8axS6QWNMm3IZ6PdKA89HE2Ju3vs0LK8="
                    }

                };

                RoleSet user = new RoleSet { Name = "Users" };
                RoleSet powerUser = new RoleSet { Name = "Power Users" };
                RoleSet admin = new RoleSet { Name = "Administrators" };

                roles = new Role[] {
                    new Role { Name = "Can_Access_Application",
                        Description = "Can access this application",
                        },
                    new Role { Name = "Can_Access_Control_Panel",
                        Description = "Can access Control Panel",
                        },
                    new Role { Name = "Can_Access_Home_Controller",
                        Description = "Can access Control's Panel Home Page",
                        },
                    new Role { Name = "Can_Access_Member_Controller",
                        Description = "Can access Member Settings",
                        },
                    new Role { Name = "Can_Create_Member",
                        Description = "Can add members",
                        },
                    new Role { Name = "Can_Edit_Member",
                        Description = "Can edit member's details",
                        },
                    new Role { Name = "Can_Delete_Member",
                        Description = "Can remove members",
                        },
                    new Role { Name = "Can_Access_Role_Controller",
                        Description = "Can access Role Settings",
                        },
                    new Role { Name = "Can_Create_Role_Set",
                        Description = "Can add roles",
                        },
                    new Role { Name = "Can_Edit_Role_Set",
                        Description = "Can edit role's settings",
                        },
                    new Role { Name = "Can_Delete_Role_Set",
                        Description = "Can remove roles" }
                };

                int currentRoles = context.Roles.Count() > 0 ? (context.Roles.Count() - 1) : 0;

                foreach (Role role in roles)
                {
                    context.Roles.Add(role);
                }

                List<RoleSetting> adminRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = true;

                    adminRoles.Add(roleValue);
                }
                admin.Roles = adminRoles;

                List<RoleSetting> powerUserRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = true;

                    powerUserRoles.Add(roleValue);
                }
                powerUser.Roles = powerUserRoles;

                List<RoleSetting> userRoles = new List<RoleSetting>();
                foreach (Role role in roles)
                {
                    RoleSetting roleValue = new RoleSetting();
                    roleValue.Role = role;
                    roleValue.IsActive = false;

                    userRoles.Add(roleValue);
                }
                user.Roles = userRoles;

                foreach (RoleSet item in new RoleSet[] { admin, powerUser, user })
                {
                    context.RoleSets.Add(item);
                }

                member.RoleSet = admin;

                context.Members.Add(member);

                context.SaveChanges();
            }
        }
コード例 #4
0
ファイル: IMRoleRepository.cs プロジェクト: cigno/ReSolution
 public void DeleteRole(RoleSet roleSet)
 {
     RoleSet roleSetToRemove = roleSets.FirstOrDefault(r => r.RoleSetId == roleSet.RoleSetId);
     roleSets.Remove(roleSetToRemove);
 }