Beispiel #1
0
        public void Add(string rolename, string description, IList<string> navlist)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                RoleInfo role = new RoleInfo();
                role.RoleInfoId = Guid.NewGuid();
                role.RoleName = rolename;
                role.Description = description;
                role.CreateTime = DateTime.Now;

                //设置权限
                setNavigation(context, role, navlist);

                //角色类型
                if (SiteManager == null)
                {
                    //如果没有站点管理角色
                    role.RoleType = (int)RoleType.SiteManager;
                }
                else
                {
                    role.RoleType = (int)RoleType.Common;
                }

                context.RoleInfoes.Add(role);

                context.LogChangesDuringSave = true;
                context.SaveChanges();
            }
        }
Beispiel #2
0
        public int ChangeState(RoleInfo role, int state)
        {
            using (var context = new WSI.DataAccess.WSICmsContext())
            {
                context.RoleInfoes.Attach(role);
                role.State = state;

                context.LogChangesDuringSave = true;
                return context.SaveChanges();
            }
        }
Beispiel #3
0
 //设置角色的权限
 private void setNavigation(DataAccess.WSICmsContext context, RoleInfo role, IList<string> navlist)
 {
     //重置为空列表
     if (role.Navigations == null)
     {
         role.Navigations = new List<Navigation>();
     }
     else
     {
         role.Navigations.Clear();
     }
     foreach (var navid in navlist)
     {
         Guid id;
         if (Guid.TryParse(navid, out id))
         {
             var nav = context.Navigations.Find(id);
             if (nav != null)
             {
                 role.Navigations.Add(nav);
             }
         }
     }
 }