コード例 #1
0
        public int DeleteMoudle(string moudleId)
        {
            using (var db = new NationalUnionContext())
            {
                var entity = db.ChannelMoudles.SingleOrDefault(cm => cm.MoudleId == moudleId);
                if (entity != null)
                {
                    // 删除ChannelRight表数据
                    var rights = db.ChannelRights.Where(cr => cr.MoudleId == moudleId).AsQueryable();
                    foreach (var right in rights)
                    {
                        // 删除ChannelRightOperate表数据
                        var operates = db.ChannelRightOperates.Where(cro => cro.RightId == right.RightId).AsQueryable();
                        foreach (var operate in operates)
                        {
                            db.ChannelRightOperates.Remove(operate);
                        }
                        db.ChannelRights.Remove(right);
                    }

                    // 删除ChannelMoudleOperate表数据
                    var menuOperates = db.ChannelMoudleOperates.Where(cmo => cmo.MoudleId == moudleId).AsQueryable();
                    foreach (var menuOperate in menuOperates)
                    {
                        db.ChannelMoudleOperates.Remove(menuOperate);
                    }

                    db.ChannelMoudles.Remove(entity);

                    return(db.SaveChanges());
                }

                return(0);
            }
        }
コード例 #2
0
        public int AddMoudleOperate(ChannelMoudleOperate entity)
        {
            using (var db = new NationalUnionContext())
            {
                db.ChannelMoudleOperates.Add(entity);

                return(db.SaveChanges());
            }
        }
コード例 #3
0
        public int AddRole(ChannelRole entity)
        {
            using (var db = new NationalUnionContext())
            {
                db.ChannelRoles.Add(entity);

                return(db.SaveChanges());
            }
        }
コード例 #4
0
        public int EditMoudleOperate(ChannelMoudleOperate entity)
        {
            using (var db = new NationalUnionContext())
            {
                db.ChannelMoudleOperates.Attach(entity);
                db.Entry(entity).State = EntityState.Modified;

                return(db.SaveChanges());
            }
        }
コード例 #5
0
        public int DeleteMoudleOperate(string moudleOperateId)
        {
            using (var db = new NationalUnionContext())
            {
                ChannelMoudleOperate entity = db.ChannelMoudleOperates.SingleOrDefault(cmo => cmo.MoudleOperateId == moudleOperateId);
                if (entity != null)
                {
                    db.ChannelMoudleOperates.Remove(entity);
                }

                return(db.SaveChanges());
            }
        }
コード例 #6
0
        public int DeleteRole(string roleId)
        {
            using (var db = new NationalUnionContext())
            {
                var entity = db.ChannelRoles.SingleOrDefault(r => r.RoleId == roleId);
                if (entity != null)
                {
                    db.ChannelRoles.Remove(entity);
                }

                return(db.SaveChanges());
            }
        }
コード例 #7
0
        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);
        }