public OpResult Publish(string verId, short state) { var obj = Get(verId); if (obj != null) { if (!obj.ProductRoles.Any()) { return(OpResult.Fail("请先配置角色!")); } obj.VerStatus = state; var list = ProductRoleVerRepository.GetQuery(o => o.ProductId == obj.ProductId && o.RoleVerId != obj.RoleVerId).ToList(); list.Where(o => o.VerStatus == obj.VerStatus).Each(o => o.Status = 2); if (state == 1)//测试 { obj.PublishDT = DateTime.Now; obj.PublishUID = CurrentUser.UID; obj.Status = 1; var source = list.OrderByDescending(o => o.VerCode).FirstOrDefault(o => o.VerCode > 0); if (source == null) { obj.VerCode = 1; } else { obj.VerCode = source.VerCode + 0.1m; } } ProductVerRepository.SaveChanges(); return(OpResult.Success()); } return(OpResult.Fail()); }
public List <Entity.ProductVer> GetProductVers() { var queryProduct = ProductVerRepository.GetQuery(); var queryModel = ProductRoleVerRepository.GetQuery(); var query = from x in queryProduct where !queryModel.Any(o => o.ProductId == x.ProductId) && x.Status == 1 select x; return(query.ToList()); }
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 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()); }
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 })); }
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 IEnumerable <dynamic> GetPageList(System.Collections.Specialized.NameValueCollection nvl, out int recordCount) { var query = ProductVerRepository.GetQuery(); var queryUse = ProductModuleVerRepository.GetQuery().Select(o => o.ProductId) .Union(ProductDictionaryVerRepository.GetQuery().Select(o => o.ProductId)) .Union(ProductDataVerRepository.GetQuery().Select(o => o.ProductId)) .Union(ProductRoleVerRepository.GetQuery().Select(o => o.ProductId)); var queryUser = UserRepository.GetQuery(); var code = nvl["code"].ToType <int?>(); var state = nvl["state"]; var q = from x in query select new { x.Id, x.ProductId, x.Name, x.SysName, x.Alias, x.CreateDT, x.CreateUID, x.Status, HasUse = queryUse.Any(o => o == x.ProductId) ? "√" : "--", StatusTitle = x.Status == 1 ? "已生效" : x.Status == 2 ? "已失效" : "未生效", x.Memo, Creater = queryUser.Where(o => o.UserId == x.CreateUID).Select(o => o.FullName).FirstOrDefault() }; if (code.HasValue) { q = q.Where(o => o.ProductId == code); } if (!state.IsNullOrEmpty()) { var st = state.Split(',').Select(o => short.Parse(o)).ToList(); q = q.Where(o => st.Contains(o.Status)); } recordCount = q.Count(); return(q.ToPageList()); }
public IEnumerable <dynamic> GetPageList(System.Collections.Specialized.NameValueCollection nvl, out int recordCount) { var query = ProductRoleVerRepository.GetQuery(); var queryProduct = ProductVerRepository.GetQuery(); var queryUser = UserRepository.GetQuery(); var productId = nvl["productId"].ToType <int?>(); var state = nvl["state"]; var verstate = nvl["verstate"]; var q = from x in query join y in queryProduct on x.ProductId equals y.ProductId select new { x.Id, x.CreateDT, x.ProductId, x.Status, x.VerStatus, x, RoleCount = x.ProductRoles.Count(), LimitCount = x.ProductRoles.SelectMany(o => o.ProductRoleDatas).Count(), y.SysName, Updater = queryUser.Where(o => o.UserId == x.UpdateUID).Select(o => o.FullName).FirstOrDefault(), Publisher = queryUser.Where(o => o.UserId == x.PublishUID).Select(o => o.FullName).FirstOrDefault() }; if (productId.HasValue) { q = q.Where(o => o.ProductId == productId); } if (!state.IsNullOrEmpty()) { var st = state.Split(',').Select(o => short.Parse(o)).ToList(); q = q.Where(o => st.Contains(o.Status)); } if (!verstate.IsNullOrEmpty()) { var st = verstate.Split(',').Select(o => short.Parse(o)).ToList(); q = q.Where(o => st.Contains(o.VerStatus)); } recordCount = q.Count(); return(q.ToPageList().Select(x => new { x.Id, x.x.RoleVerId, x.ProductId, x.SysName, x.x.VerCode, x.CreateDT, x.x.CreateUID, x.Status, x.VerStatus, x.x.UpdateDT, x.x.PublishDT, x.x.StatusTitle, x.x.VerStatusTitle, x.RoleCount, x.LimitCount, x.Updater, x.Publisher })); }
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); } }
public Entity.ProductRoleVer Get(string verId) { return(ProductRoleVerRepository.GetQuery(o => o.RoleVerId == verId).Include(o => o.ProductRoles).Include("ProductRoles.ProductRoleDatas").FirstOrDefault()); }
public OpResult SaveVer(Entity.ProductPublishVer obj) { if (ProductPublishVerRepository.IsExists(o => o.ProductId == obj.ProductId && o.VerStatus == 0 && o.Id != obj.Id)) { return(OpResult.Fail("已存在未发布的版本")); } if (obj.HasModelId == "1") { if (obj.ModuleId.IsNullOrEmpty()) { var model = ProductModuleVerRepository.GetOfficialLast(obj.ProductId); if (model == null) { return(OpResult.Fail("功能升级未发布正式版!")); } obj.ModuleId = model.ModuleId; } } else { obj.ModuleId = ""; } if (obj.HasRoleId == "1") { if (obj.RoleId.IsNullOrEmpty()) { var model = ProductRoleVerRepository.GetOfficialLast(obj.ProductId); if (model == null) { return(OpResult.Fail("角色升级未发布正式版!")); } obj.RoleId = model.RoleVerId; } } else { obj.RoleId = ""; } if (obj.HasDictId == "1") { if (obj.DictId.IsNullOrEmpty()) { var model = ProductDictionaryVerRepository.GetOfficialLast(obj.ProductId); if (model == null) { return(OpResult.Fail("字典升级未发布正式版!")); } obj.DictId = model.DictId; } } else { obj.DictId = ""; } if (obj.HasDataId == "1") { if (obj.DataId.IsNullOrEmpty()) { var model = ProductDataVerRepository.GetOfficialLast(obj.ProductId); if (model == null) { return(OpResult.Fail("初始数据升级未发布正式版!")); } obj.DataId = model.DataId; } } else { obj.DataId = ""; } return(SaveOrUpdate(obj)); }