示例#1
0
        public Role CreateRole(Role roleToAdd)
        {
            if (roleToAdd == null)
                return null;

            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var r = context.Roles.Add(new Role()
                    {
                        Label = roleToAdd.Label,
                        Users = new List<User>(),
                        RoleModules = new List<RoleModule>()
                    });
                context.SaveChanges();

                foreach(RoleModule rm in roleToAdd.RoleModules)
                {
                    context.RoleModules.Add(new RoleModule() {
                        Role_id = r.Id,
                        Module_id = rm.Module_id
                    });
                }

                context.SaveChanges();
                return r;
            }
        }
示例#2
0
        public void TestGetMainMenuNotImplemented()
        {
            CopyDll("MainMenuNotImplemented.dll");

            DllManager dllManager = new DllManager();
            Role role = new Role()
            {
                RoleModules = new List<RoleModule>()
                {
                    new RoleModule()
                    {
                        Module = new Module()
                        {
                            Name = "MainMenuNotImplemented"
                        }
                    }
                }
            };

            try
            {
                List<IMainMenu> mainMenus = dllManager.GetMainMenus(role);
                Assert.Fail();
            }
            catch (MainMenuNotImplementedException e1)
            {
                Assert.IsNotNull(e1);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
示例#3
0
        /// <summary>
        /// Permet de récuperer tous les menus et sous-menus des modules auxquels l'utilisateur a accès
        /// </summary>
        /// <param name="userRole">Role de l'utilsateur courant</param>
        /// <returns>Liste de IMainMenu</returns>
        public List<IMainMenu> GetMainMenus(Role userRole)
        {
            List<IMainMenu> mainMenus = new List<IMainMenu>();
            IEnumerable<string> paths = GetDllsPaths();

            foreach (string p in paths)
            {
                if (userRole.RoleModules.Any(x => x.Module.Name == Path.GetFileNameWithoutExtension(p)))
                {
                    IMainMenu mainMenu = GetMainMenu(p);

                    if (mainMenu != null && mainMenu is IMainMenu)
                    {
                        mainMenus.Add(mainMenu);
                    }
                }
            }

            return mainMenus;
        }
示例#4
0
        private Role CreateTestRole()
        {
            Role newRole = new Role();
            newRole.Label = "Role de test";

            RoleModule rm = userService.GetModules().First().RoleModules.First();
            newRole.RoleModules.Add(new RoleModule() {
                  Module = rm.Module,
                  Module_id = rm.Module_id,
                  Role = rm.Role,
                  Role_id = rm.Role_id
                });

            return userService.CreateRole(newRole);
        }
示例#5
0
 public Role EditRole(Role roleToEdit)
 {
     return userBLL.EditRole(roleToEdit);
 }
示例#6
0
 public Role CreateRole(Role roleToAdd)
 {
     return userBLL.CreateRole(roleToAdd);
 }
示例#7
0
        public Role EditRole(Role roleToEdit)
        {
            if (roleToEdit == null)
                return null;

            var listToAdd = new List<RoleModule>();

            using (SUPERPEntities context = new SUPERPEntities(false))
            {
                var r = context.Roles.Include("RoleModules").Include("RoleModules.Module").Include("RoleModules.Role").FirstOrDefault(x => x.Id == roleToEdit.Id);
                if (r == null)
                    return null;

                context.RoleModules.RemoveRange(r.RoleModules);
                context.SaveChanges();
                r.RoleModules.Clear();
                foreach (var rm in roleToEdit.RoleModules)
                {
                    RoleModule rrm = null;
                    if ((rrm = r.RoleModules.FirstOrDefault(x => x.Id == rm.Id)) == null)
                    {
                        listToAdd.Add(new RoleModule()
                        {
                            Module_id = rm.Module_id,
                            Role_id = rm.Role_id
                        });
                    }
                }

                context.RoleModules.AddRange(listToAdd);

                r.Label = roleToEdit.Label;
                context.SaveChanges();
                return r;
            }
        }
示例#8
0
        public void TestGetMainMenus()
        {
            DllManager dllManager = new DllManager();
            Role role = new Role()
            {
                RoleModules = new List<RoleModule>()
                {
                    new RoleModule()
                    {
                        Module = new Module()
                        {
                            Name = "SupErpModuleUser"
                        }
                    }
                }
            };

            List<IMainMenu> mainMenus = dllManager.GetMainMenus(role);
            Assert.IsNotNull(mainMenus);
            Assert.AreEqual(1, mainMenus.Count);
            Assert.AreEqual("Administration", mainMenus[0].MenuName);
            Assert.IsTrue(mainMenus[0].SubMenus.Count > 0);
        }