public void MoveMenuItem(short mode, int menuId, int roleId, string verId) { var ver = Get(verId); var role = ver.ProductRoles.FirstOrDefault(o => o.RoleId == roleId); var obj = role.ProductRoleDatas.FirstOrDefault(o => o.MenuId == menuId); var list = role.ProductRoleDatas.Where(o => o.PMenuId == obj.PMenuId).OrderBy(o => o.SortOrder).ToList(); switch (mode) { case 2: //下移 var obj1 = list.LastOrDefault(); if (obj.Id != obj1.Id) { Entity.ProductRoleData 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; obj.SortOrder = next.SortOrder; next.SortOrder = sort; ProductRoleVerRepository.SaveChanges(); } } break; default: //上移 var obj2 = list.FirstOrDefault(); if (obj.Id != obj2.Id) { Entity.ProductRoleData 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; obj.SortOrder = prev.SortOrder; prev.SortOrder = sort; ProductRoleVerRepository.SaveChanges(); } } break; } }
public OpResult SaveOrUpdate(ProductRoleVer obj) { if (obj.Id == 0) { obj.RoleVerId = CommonService.GUID; obj.CreateDT = DateTime.Now; obj.UpdateDT = obj.CreateDT; obj.UpdateUID = CurrentUser.UID; obj.CreateUID = obj.UpdateUID; ProductRoleVerRepository.Add(obj, false); } else { var product = ProductRoleVerRepository.Find(o => o.Id == obj.Id); product.UpdateUID = CurrentUser.UID; product.UpdateDT = DateTime.Now; } ProductRoleVerRepository.SaveChanges(); return(OpResult.Success()); }
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); } }