Esempio n. 1
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public void Insert(Role roles)
        {
            using (Entities db = new Entities())
            {
                base_roles roleEnd = new base_roles();
                roleEnd.id          = roles.ID;
                roleEnd.name        = roles.Name;
                roleEnd.issystem    = 0;
                roleEnd.seqno       = roles.SeqNo;
                roleEnd.updatedtime = DateTime.Now;
                roleEnd.createdtime = DateTime.Now;
                roleEnd.comment     = roles.Comment;
                db.base_roles.Add(roleEnd);
                db.SaveChanges();

                foreach (string permissionCode in roles.PermissionCodeArr)
                {
                    base_rolepermissions newRp = new base_rolepermissions()
                    {
                        roleid         = roleEnd.id,
                        permissioncode = permissionCode
                    };
                    db.base_rolepermissions.Add(newRp);
                }

                db.SaveChanges();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="roles"></param>
        /// <returns></returns>
        public void Edit(Role roles)
        {
            using (Entities db = new Entities())
            {
                base_roles rolesEdit = db.base_roles.Find(roles.ID);
                if (rolesEdit != null)
                {
                    rolesEdit.name        = roles.Name;
                    rolesEdit.comment     = roles.Comment;
                    rolesEdit.seqno       = roles.SeqNo;
                    rolesEdit.updatedtime = DateTime.Now;

                    //删除现有角色权限
                    List <base_rolepermissions> rpList = db.base_rolepermissions.Where(t => t.roleid == roles.ID && !t.permissioncode.Contains("PHONE_")).ToList();

                    if (rpList.Count > 0)
                    {
                        foreach (var rp in rpList)
                        {
                            db.base_rolepermissions.Remove(rp);
                        }
                    }

                    //添加新角色权限
                    foreach (string permissionCode in roles.PermissionCodeArr)
                    {
                        base_rolepermissions newRp = new base_rolepermissions()
                        {
                            roleid         = rolesEdit.id,
                            permissioncode = permissionCode
                        };
                        db.base_rolepermissions.Add(newRp);
                    }
                    db.SaveChanges();
                }
            }
        }