Example #1
0
        public OpResult Deletes(int[] ids)
        {
            var list = RoleRepository.GetQuery(o => ids.Contains(o.Id)).Include(o => o.SysRoleDatas).ToList();

            RoleDataRepository.RemoveRange(list.SelectMany(o => o.SysRoleDatas).ToList(), false);
            RoleRepository.RemoveRange(list);
            return(OpResult.Success());
        }
Example #2
0
        public List <Models.ProductRoleMenuModel> FindMenuList(int?roleId)
        {
            var queryMenu = MenuRepository.GetQuery(o => o.Status);
            var ms        = new List <Models.ProductRoleMenuModel>();

            if (roleId > 0)
            {
                var queryRole     = RoleRepository.GetQuery(o => o.RoleId == roleId);
                var queryRoleData = RoleDataRepository.GetQuery(o => o.RoleId == roleId);
                var q             = from x in queryMenu
                                    join y in queryRoleData on x.MenuId equals y.MenuId into tmp
                                    from z in tmp.DefaultIfEmpty()
                                    orderby z.SortOrder
                                    select new Models.ProductRoleMenuModel()
                {
                    Id           = x.MenuId,
                    MenuId       = x.MenuId,
                    PMenuId      = x.PMenuId,
                    Title        = x.Title,
                    LimitSelects = queryRole.Select(i => i.Limitids).FirstOrDefault(),
                    ParentId     = z.HasSelected ? 1 : 0
                };
                ms = q.ToList();
            }
            else
            {
                ms = queryMenu.OrderBy(o => o.SortOrder).Select(x => new Models.ProductRoleMenuModel()
                {
                    Id      = x.MenuId,
                    MenuId  = x.MenuId,
                    PMenuId = x.PMenuId,
                    Title   = x.Title
                }).ToList();
            }
            var limits = LimitRepository.GetQuery(o => o.Status).OrderBy(o => o.SortOrder).ToList();

            ms.Each(o =>
            {
                o.Limitids      = string.Join(",", limits.Where(i => i.PLimitId == o.MenuId).Select(i => i.Title + ":" + i.LimitId));
                o.MenuIdSelects = string.Join(",", ms.Where(i => i.ParentId == 1).Select(i => i.MenuId));
            });
            ms.Each(o =>
            {
                o.ParentId = 0;
            });
            var list = new List <Models.ProductRoleMenuModel>();

            foreach (var menu in ms.Where(o => o.PMenuId <= 0))
            {
                SetChilds(menu, ms);
                menu.Index = list.Count;
                list.Add(menu);
            }
            return(list);
        }
Example #3
0
        public void MoveMenuItems(short mode, int menuId, string roleId)
        {
            var ids       = roleId.Split(',').Select(o => int.Parse(o)).ToArray();
            var roleDatas = RoleDataRepository.GetQuery(o => ids.Contains(o.RoleId)).ToList();
            var obj       = roleDatas.FirstOrDefault(o => o.RoleId == ids[0] && o.MenuId == menuId);
            var list      = roleDatas.Where(o => o.RoleId == ids[0] && o.PMenuId == obj.PMenuId).OrderBy(o => o.SortOrder).ToList();

            switch (mode)
            {
            case 2:    //下移
                var obj1 = list.LastOrDefault();
                if (obj.Id != obj1.Id)
                {
                    Entity.SysRoleData next = null;
                    for (var i = 0; i < list.Count; i++)
                    {
                        if (obj.Id == list[i].Id)
                        {
                            next = list[i + 1]; break;
                        }
                    }
                    if (next != null)
                    {
                        var sort = obj.SortOrder;
                        roleDatas.Where(o => o.MenuId == obj.MenuId).Each(o => o.SortOrder  = next.SortOrder);
                        roleDatas.Where(o => o.MenuId == next.MenuId).Each(o => o.SortOrder = sort);
                        RoleRepository.SaveChanges();
                    }
                }
                break;

            default:    //上移
                var obj2 = list.FirstOrDefault();
                if (obj.Id != obj2.Id)
                {
                    Entity.SysRoleData prev = null;
                    for (var i = 0; i < list.Count; i++)
                    {
                        if (obj.Id == list[i].Id)
                        {
                            prev = list[i - 1]; break;
                        }
                    }
                    if (prev != null)
                    {
                        var sort = obj.SortOrder;
                        roleDatas.Where(o => o.MenuId == obj.MenuId).Each(o => o.SortOrder  = prev.SortOrder);
                        roleDatas.Where(o => o.MenuId == prev.MenuId).Each(o => o.SortOrder = sort);
                        RoleRepository.SaveChanges();
                    }
                }
                break;
            }
        }
Example #4
0
        public List <SysMenuLimitModel> GetUserMenus(string userId)
        {
            var list = new List <SysMenuLimitModel>();

            if (UserRepository == null)
            {
                UserRepository = NinjectObject.GetFromMVC <DAL.BaseRepository <SysUser> >();
            }
            if (MenuRepository == null)
            {
                MenuRepository = NinjectObject.GetFromMVC <DAL.BaseRepository <SysMenus> >();
            }
            if (RoleDataRepository == null)
            {
                RoleDataRepository = NinjectObject.GetFromMVC <DAL.BaseRepository <SysRoleData> >();
            }
            if (RoleRepository == null)
            {
                RoleRepository = NinjectObject.GetFromMVC <DAL.BaseRepository <SysRoles> >();
            }
            var user = UserRepository.Find(o => o.UserId == userId);

            if (user != null)
            {
                if (user.IsSuper)
                {
                    list = MenuRepository.GetQuery(o => o.Status).OrderBy(o => o.SortOrder).Select(y => new SysMenuLimitModel()
                    {
                        Id         = y.Id,
                        MenuId     = y.MenuId,
                        PMenuId    = y.PMenuId,
                        SortOrder  = y.SortOrder,
                        Status     = y.Status,
                        Title      = y.Title,
                        URL        = y.URL,
                        LimitIdStr = "-1"
                    }).ToList();
                }
                else if (!user.RoleIds.IsNullOrEmpty())
                {
                    var rids      = user.RoleIds.ToIntArray();
                    var queryRole = RoleRepository.GetQuery();
                    var queryMenu = MenuRepository.GetQuery();
                    var queryData = RoleDataRepository.GetQuery();
                    var query     = from x in queryData
                                    join y in queryMenu on x.MenuId equals y.MenuId
                                    join z in queryRole on x.RoleId equals z.RoleId
                                    where y.Status && z.Status && rids.Contains(x.RoleId) && x.HasSelected
                                    orderby x.SortOrder
                                    select new SysMenuLimitModel()
                    {
                        Id         = y.Id,
                        MenuId     = y.MenuId,
                        PMenuId    = y.PMenuId,
                        Status     = y.Status,
                        Title      = y.Title,
                        URL        = y.URL,
                        SortOrder  = x.SortOrder,
                        LimitIdStr = z.Limitids
                    };
                    list = query.ToList();
                }
            }
            return(list);
        }
Example #5
0
        public OpResult UpdateData()
        {
            ProductPublishVer ver = null;

            try
            {
                using (TransactionScope tran = new TransactionScope())
                {
                    ver = PublishVerService.UpdatePublish(0, 1, CurrentUser.FullName);
                    if (ver.ProductModuleVer != null)
                    {
                        var menus  = new List <SysMenus>();
                        var limits = new List <SysLimits>();
                        ver.ProductModuleVer.ProductMenuLimits.Each(o =>
                        {
                            switch (o.Type)
                            {
                            case 1:
                                menus.Add(new SysMenus()
                                {
                                    MenuId = o.MenuId, PMenuId = o.PMenuId, SortOrder = o.SortOrder, Status = o.Status, Title = o.Title, URL = o.Url
                                });
                                break;

                            case 3:
                                limits.Add(new SysLimits()
                                {
                                    LimitId = o.MenuId, PLimitId = o.PMenuId, SortOrder = o.SortOrder, Status = o.Status, Title = o.Title
                                });
                                break;

                            default:
                                break;
                            }
                        });
                        if (menus.Any())
                        {
                            var list = MenuRepository.GetQuery().ToList();
                            MenuRepository.RemoveRange(list);
                            MenuRepository.AddRange(menus);
                        }
                        if (limits.Any())
                        {
                            LimitRepository.RemoveRange(LimitRepository.GetQuery().ToList());
                            LimitRepository.AddRange(limits);
                        }
                    }
                    if (ver.ProductRoleVer != null)
                    {
                        var roles = new List <SysRoles>();
                        ver.ProductRoleVer.ProductRoles.Each(o =>
                        {
                            var role          = new SysRoles();
                            role.CreateDT     = DateTime.Now;
                            role.CreateUID    = CurrentUser.UID;
                            role.RoleId       = o.RoleId.GetValueOrDefault();
                            role.Title        = o.Title;
                            role.Limitids     = o.Limitids;
                            role.Type         = 0;
                            role.Status       = true;
                            role.UpdateDT     = role.CreateDT;
                            role.UpdateUID    = role.CreateUID;
                            role.SysRoleDatas = new List <SysRoleData>();
                            o.ProductRoleDatas.Each(i =>
                            {
                                role.SysRoleDatas.Add(new SysRoleData()
                                {
                                    HasSelected = i.HasSelected,
                                    MenuId      = i.MenuId,
                                    PMenuId     = i.PMenuId,
                                    SortOrder   = i.SortOrder
                                });
                            });
                            roles.Add(role);
                        });
                        if (roles.Any())
                        {
                            var list = RoleRepository.GetQuery(o => o.Type == 0).Include(o => o.SysRoleDatas).ToList();
                            roles.Each(o => {
                                var r = list.FirstOrDefault(i => i.RoleId == o.RoleId);
                                if (r != null)
                                {
                                    o.DeptId = r.DeptId;
                                    if (!r.Memo.IsNullOrEmpty())
                                    {
                                        o.Memo = r.Memo;
                                    }
                                    o.Status    = r.Status;
                                    o.CreateDT  = r.CreateDT;
                                    o.CreateUID = r.CreateUID;
                                }
                            });
                            RoleDataRepository.RemoveRange(list.SelectMany(o => o.SysRoleDatas).ToList());
                            RoleRepository.RemoveRange(list);
                            RoleRepository.AddRange(roles);
                        }
                    }
                    if (ver.ProductDictionaryVer != null)
                    {
                        var dicts = new List <SysDataDictionary>();
                        ver.ProductDictionaryVer.ProductDictionaryDatas.Each(o =>
                        {
                            dicts.Add(new SysDataDictionary()
                            {
                                CreateDT  = DateTime.Now,
                                CreateUID = CurrentUser.UID,
                                Depth     = o.Depth,
                                DicPSN    = o.DicPSN,
                                DicSN     = o.DicSN,
                                HasChild  = o.HasChild,
                                SortOrder = o.SortOrder,
                                Status    = Convert.ToBoolean(o.Status),
                                Title     = o.Title
                            });
                        });
                        if (dicts.Any())
                        {
                            var list = DictRepository.GetQuery().ToList();
                            DictRepository.RemoveRange(list);
                            DictRepository.AddRange(dicts);
                        }
                    }
                    var sqls = new Dictionary <int, string>();
                    var db   = new DBFramework.DBHelper();
                    if (ver.ProductDataVer != null)
                    {
                        ver.ProductDataVer.ProductDataSqls.OrderBy(o => o.RunSort).Each(o =>
                        {
                            sqls[o.MenuId] = o.RunSql;
                        });
                        foreach (var de in sqls)
                        {
                            try
                            {
                                db.ExecuteNonQueryText(de.Value, null);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("更新初始化数据失败!MenuId:" + de.Key + ";" + LogEngine.ToInnerException(ex).Message);
                            }
                        }
                        sqls.Clear();
                    }
                    ver.ProductPublishSqls.OrderBy(o => o.RunSort).Each(o =>
                    {
                        sqls[o.MenuId] = o.RunSql;
                    });
                    foreach (var de in sqls)
                    {
                        try
                        {
                            db.ExecuteNonQueryText(de.Value, null);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("历史数据处理失败!MenuId:" + de.Key + ";" + LogEngine.ToInnerException(ex).Message);
                        }
                    }
                    tran.Complete();
                }
            }catch (Exception e)
            {
                LogEngine.WriteError(e);
                if (ver != null)
                {
                    PublishVerService.AddUpdateLog(ver.PublishId, 0, false, LogEngine.ToInnerException(e).Message, CurrentUser.FullName);
                }
                return(OpResult.Fail());
            }
            return(OpResult.Success());
        }