Пример #1
0
        public OpResult SaveLimits(string verId, int roleId, string menuIds, string limitIds)
        {
            var ver = Get(verId);

            if (ver == null)
            {
                return(OpResult.Fail());
            }
            var role = ver.ProductRoles.FirstOrDefault(o => o.RoleId == roleId);

            if (role == null)
            {
                return(OpResult.Fail());
            }
            role.Limitids = limitIds;
            var mids = menuIds.Split(',').Where(o => !o.IsNullOrEmpty()).Select(o => int.Parse(o));

            role.ProductRoleDatas.Each(o => {
                o.HasSelected = mids.Any(i => i == o.MenuId);
            });
            ver.UpdateDT  = DateTime.Now;
            ver.UpdateUID = CurrentUser.UID;
            ProductRoleRepository.SaveChanges();
            return(OpResult.Success());
        }
Пример #2
0
        public OpResult RemoveRole(int[] ids)
        {
            var list = ProductRoleRepository.GetQuery(o => ids.Contains(o.Id)).Include(o => o.ProductRoleDatas).ToList();

            ProductRoleDataRepository.RemoveRange(list.SelectMany(o => o.ProductRoleDatas).ToList(), false);
            ProductRoleRepository.RemoveRange(list);
            return(OpResult.Success());
        }
Пример #3
0
        public OpResult Deletes(int[] ids)
        {
            var list = ProductRoleVerRepository.GetQuery(o => ids.Contains(o.Id)).Include(o => o.ProductRoles).Include("ProductRoles.ProductRoleDatas").ToList();

            if (list.Any(o => o.VerStatus > 0))
            {
                return(OpResult.Fail("该状态不允许删除!"));
            }
            ProductRoleDataRepository.RemoveRange(list.SelectMany(o => o.ProductRoles.SelectMany(i => i.ProductRoleDatas)).ToList(), false);
            ProductRoleRepository.RemoveRange(list.SelectMany(o => o.ProductRoles).ToList(), false);
            ProductRoleVerRepository.RemoveRange(list);
            return(OpResult.Success());
        }
Пример #4
0
        public IEnumerable <dynamic> RoleList(string verId)
        {
            var queryRole = ProductRoleRepository.GetQuery(o => o.RoleVerId == verId);
            var queryUser = UserRepository.GetQuery();
            var q         = from x in queryRole
                            select new {
                x.Id,
                x.RoleId,
                x.Title,
                x.CreateDT,
                x.CreateUID,
                Creater = queryUser.Where(o => o.UserId == x.CreateUID).Select(o => o.FullName).FirstOrDefault(),
            };

            return(q.ToList());
        }
Пример #5
0
 public OpResult SaveRole(ProductRole obj)
 {
     if (obj.Id == 0)
     {
         obj.RoleId    = ProductRoleRepository.GetMaxInt(o => o.RoleId, whereLambda: o => o.RoleVerId == obj.RoleVerId);
         obj.CreateDT  = DateTime.Now;
         obj.CreateUID = CurrentUser.UID;
         ProductRoleRepository.Add(obj, false);
     }
     else
     {
         var role = ProductRoleRepository.Get(obj.Id);
         role.Title = obj.Title;
     }
     ProductRoleRepository.SaveChanges();
     return(OpResult.Success());
 }
Пример #6
0
        public OpResult SaveRole(string roleVerId, string moduleId, int?productId, string title)
        {
            if (ProductRoleVerRepository.IsExists(o => o.ProductId == productId && o.Status == 0 && o.RoleVerId != roleVerId))
            {
                return(OpResult.Fail("已存在未发布的版本"));
            }
            var verId = roleVerId.IsNullOrEmpty() ? CommonService.GUID : roleVerId;

            if (ProductRoleRepository.IsExists(o => o.RoleVerId == verId && o.Title == title))
            {
                return(OpResult.Fail("该角色已存在!"));
            }
            var role = new ProductRole()
            {
                Title     = title,
                RoleVerId = verId,
                RoleId    = ProductRoleRepository.GetMaxInt(o => o.RoleId, whereLambda: o => o.RoleVerId == verId),
                CreateDT  = DateTime.Now,
                CreateUID = CurrentUser.UID
            };
            var ver = ProductRoleVerRepository.Find(o => o.RoleVerId == verId);

            if (ver == null)
            {
                ver = new ProductRoleVer()
                {
                    ModuleId  = moduleId,
                    ProductId = productId.GetValueOrDefault(),
                    RoleVerId = verId,
                };
                ver.UpdateDT  = ver.CreateDT = role.CreateDT;
                ver.UpdateUID = ver.CreateUID = role.CreateUID;
                ProductRoleVerRepository.Add(ver, false);
            }
            else
            {
                ver.ModuleId = moduleId;
            }
            ProductRoleRepository.Add(role, false);
            ProductRoleRepository.SaveChanges();
            return(OpResult.Success(data: new{ verId = verId, roleId = role.RoleId }));
        }
Пример #7
0
 public ProductRole GetRole(int id)
 {
     return(ProductRoleRepository.Get(id));
 }
Пример #8
0
        public List <Models.ProductRoleMenuModel> FindMenuList(int productId, int roleId, string verId, bool isdetail)
        {
            lock (_objlock)
            {
                var queryMenu     = ProductMenuLimitRepository.GetQuery();
                var queryRoleVer  = ProductRoleVerRepository.GetQuery(o => o.RoleVerId == verId);
                var queryRole     = ProductRoleRepository.GetQuery(o => o.RoleId == roleId);
                var queryRoleData = ProductRoleDataRepository.GetQuery();
                var ver           = Get(verId);
                var ms            = new List <Models.ProductRoleMenuModel>();
                if (ver != null && !ver.ModuleId.IsNullOrEmpty())
                {
                    queryMenu = queryMenu.Where(o => o.ModuleId == ver.ModuleId);
                    var q = from x in queryRoleData
                            join z in queryRole on x.RoleDataId equals z.Id
                            join y in queryMenu on x.MenuId equals y.MenuId
                            where z.RoleVerId == verId && queryRoleVer.Any(o => o.ModuleId == y.ModuleId)
                            orderby x.SortOrder
                            select new Models.ProductRoleMenuModel()
                    {
                        Id           = y.MenuId,
                        MenuId       = y.MenuId,
                        PMenuId      = y.PMenuId,
                        Title        = y.Title,
                        LimitSelects = z.Limitids,
                        ParentId     = x.HasSelected ? 1 : 0
                    };
                    ms = q.ToList();
                    var limits = queryMenu.Where(o => o.Type == 3).ToList();
                    ms.Each(o =>
                    {
                        o.Limitids      = string.Join(",", limits.Where(i => i.PMenuId == o.MenuId).Select(i => i.Title + ":" + i.MenuId));
                        o.MenuIdSelects = string.Join(",", ms.Where(i => i.ParentId == 1).Select(i => i.MenuId));
                    });
                    ms.Each(o =>
                    {
                        o.ParentId = 0;
                    });
                }
                if (!ms.Any())
                {
                    var modelVer = ProductModelVerService.GetOfficialLast(productId);
                    if (modelVer != null && ver != null)
                    {
                        var role = ver.ProductRoles.FirstOrDefault(o => o.RoleId == roleId);
                        if (!role.ProductRoleDatas.Any())
                        {
                            role.ProductRoleDatas.AddRange(modelVer.ProductMenuLimits.Where(o => o.Type != 3).Select(o => new ProductRoleData()
                            {
                                PMenuId   = o.PMenuId,
                                MenuId    = o.MenuId,
                                SortOrder = o.SortOrder,
                            }));
                            ver.ModuleId = modelVer.ModuleId;
                            ProductRoleVerRepository.SaveChanges();
                        }

                        ms.AddRange(modelVer.ProductMenuLimits.Where(o => o.Type != 3).OrderBy(o => o.SortOrder).Select(o => new Models.ProductRoleMenuModel()
                        {
                            Id       = o.MenuId,
                            MenuId   = o.MenuId,
                            PMenuId  = o.PMenuId,
                            Title    = o.Title,
                            Limitids = string.Join(",", modelVer.ProductMenuLimits.Where(i => i.PMenuId == o.MenuId && i.Type == 3).Select(i => i.Title + ":" + i.MenuId))
                        }));
                    }
                }
                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);
            }
        }