Esempio n. 1
0
        public void SaveMenuRoles(int menuId, string[] selectedRoles)
        {
            foreach (string item in selectedRoles)
            {
                MenuRole menuRole = new MenuRole
                {
                    MenuId = menuId,
                    RoleId = item
                };

                ContextPerRequest.CurrentData.MenuRoles.Add(menuRole);
                ContextPerRequest.CurrentData.SaveChanges();
            }
        }
Esempio n. 2
0
        public void SaveEditMenuRoles(int menuId, string[] selectedRoles)
        {
            var dataDeleteMenuRoles = (from roles in ContextPerRequest.CurrentData.MenuRoles
                                       where roles.MenuId == menuId
                                       select roles);

            foreach (var item in dataDeleteMenuRoles)
            {
                ContextPerRequest.CurrentData.MenuRoles.Remove(item);
            }
            ContextPerRequest.CurrentData.SaveChanges();

            foreach (string item in selectedRoles)
            {
                MenuRole menuRole = new MenuRole
                {
                    MenuId = menuId,
                    RoleId = item
                };

                ContextPerRequest.CurrentData.MenuRoles.Add(menuRole);
                ContextPerRequest.CurrentData.SaveChanges();
            }
        }