public int UpdatePermission(ChannelRightOperate entity)
        {
            var rightOperate = new ChannelRightOperate
            {
                RightOperateId = entity.RightOperateId,
                RightId        = entity.RightId,
                KeyCode        = entity.KeyCode,
                IsValid        = entity.IsValid
            };

            // 判断rightOperate是否存在,如果存在就更新rightOperate,否则就添加一条
            using (var db = new NationalUnionContext())
            {
                ChannelRightOperate rightOpt = db.ChannelRightOperates.FirstOrDefault(ro => ro.RightOperateId == rightOperate.RightOperateId);
                if (rightOpt != null)
                {
                    rightOpt.IsValid = rightOperate.IsValid;
                }

                db.ChannelRightOperates.Add(rightOperate);

                if (db.SaveChanges() > 0)
                {
                    // 更新角色--模块的有效标志RightFlag
                    var right = (from rt in db.ChannelRights
                                 where rt.RightId == rightOperate.RightId
                                 select rt).First();

                    // 根据right.MoudleId right.RoleId,计算上级模块的RightFlag
                    var count = db.ChannelRightOperates.Count(ro => ro.RightId == (right.RoleId + right.MoudleId) && ro.IsValid == 1);
                    var rgt   = db.ChannelRights.FirstOrDefault(r => r.RoleId == right.RoleId && r.MoudleId == right.MoudleId);
                    if (rgt != null)
                    {
                        if (count > 0)
                        {
                            rgt.RightFlag = 1;
                        }

                        rgt.RightFlag = 0;
                    }

                    string parentId = right.MoudleId;
                    while (parentId != null && parentId != "0")
                    {
                        var moudles = db.ChannelMoudles.Select(cm => cm.ParentId == parentId);
                        if (moudles.Any())
                        {
                            var objcount = (from cm in db.ChannelMoudles
                                            where cm.ParentId == parentId
                                            from cr in db.ChannelRights
                                            where cr.RoleId == right.RoleId
                                            where cr.MoudleId == cm.MoudleId
                                            where cr.RightFlag == 1
                                            select cr).Count();

                            var crgt = db.ChannelRights.FirstOrDefault(r => r.MoudleId == parentId && r.RoleId == right.RoleId);
                            if (crgt != null)
                            {
                                if (objcount > 0)
                                {
                                    crgt.RightFlag = 1;
                                }

                                crgt.RightFlag = 0;
                            }
                        }
                    }
                    return(1);
                }
                db.SaveChanges();
            }

            return(0);
        }
 public int UpdatePermission(ChannelRightOperate model)
 {
     return(ChannelPermissionBll.UpdatePermission(model));
 }
 /// <summary>
 /// 更新权限
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public int UpdatePermission(ChannelRightOperate entity)
 {
     return(ChannelPermissionRepository.UpdatePermission(entity));
 }