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 })); }