当前位置: 首页>>代码示例>>C#>>正文


C# Guid.Except方法代码示例

本文整理汇总了C#中System.Guid.Except方法的典型用法代码示例。如果您正苦于以下问题:C# Guid.Except方法的具体用法?C# Guid.Except怎么用?C# Guid.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Guid的用法示例。


在下文中一共展示了Guid.Except方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateMenu

        public MenuResult UpdateMenu(AuthIdentity identity, Guid? menuId, Guid[] recipesAdd, Guid[] recipesRemove, MenuMove[] recipesMove, bool clear, string newName = null)
        {
            var ret = new MenuResult();
             ret.MenuUpdated = true; // TODO: Verify actual changes were made before setting MenuUpdated to true

             using (var session = GetSession())
             {
            using (var transaction = session.BeginTransaction())
            {
               Models.Menus dbMenu = null;
               IList<Favorites> dbRecipes = null;
               if (menuId.HasValue)
               {
                  dbMenu = session.QueryOver<Models.Menus>()
                     .Fetch(prop => prop.Recipes).Eager
                     .Where(p => p.MenuId == menuId)
                     .SingleOrDefault();

                  if (dbMenu == null)
                     throw new MenuNotFoundException();

                  if (dbMenu.UserId != identity.UserId) // User does not have access to modify this menu
                     throw new UserDoesNotOwnMenuException();

                  if (!String.IsNullOrWhiteSpace(newName) && dbMenu != null) // Rename menu
                     dbMenu.Title = newName.Trim();

                  dbRecipes = dbMenu.Recipes;
               }
               else
               {
                  dbRecipes = session.QueryOver<Favorites>()
                     .Where(p => p.UserId == identity.UserId)
                     .Where(p => p.Menu == null)
                     .List();
               }

               if (recipesAdd.Any()) // Add recipes to menu
               {
                  var existing = (from r in dbRecipes select r.Recipe.RecipeId);
                  recipesAdd = recipesAdd.Except(existing).ToArray(); //Remove dupes

                  foreach (var rid in recipesAdd)
                  {
                     var fav = new Favorites
                     {
                        UserId = identity.UserId,
                        Recipe = new Models.Recipes() {RecipeId = rid},
                        Menu = dbMenu
                     };

                     session.Save(fav);
                  }
               }

               if (recipesRemove.Any()) // Remove recipes from menu
               {
                  var toDelete = (from r in dbRecipes where recipesRemove.Contains(r.Recipe.RecipeId) select r);
                  toDelete.ForEach(session.Delete);
               }

               if (clear) // Remove every recipe from menu
               {
                  dbRecipes.ForEach(session.Delete);
               }

               if (recipesMove.Any()) // Move items to another menu
               {
                  foreach (var moveAction in recipesMove)
                  {
                     Models.Menus dbTarget = null;
                     if (moveAction.TargetMenu.HasValue)
                     {
                        dbTarget = session.QueryOver<Models.Menus>()
                           .Where(p => p.MenuId == moveAction.TargetMenu.Value)
                           .Where(p => p.UserId == identity.UserId)
                           .SingleOrDefault();

                        if (dbTarget == null)
                           throw new MenuNotFoundException(moveAction.TargetMenu.Value);
                     }

                     var rToMove = (moveAction.MoveAll
                        ? dbRecipes
                        : dbRecipes.Where(r => moveAction.RecipesToMove.Contains(r.Recipe.RecipeId)));

                     rToMove.ForEach(a => a.Menu = dbTarget);
                  }
               }

               transaction.Commit();
            }
             }

             return ret;
        }
开发者ID:relimited,项目名称:core,代码行数:96,代码来源:DatabaseAdapter.cs

示例2: AddRecipesToMenu

        private static void AddRecipesToMenu(
            AuthorIdentity identity, 
            Guid[] recipesAdd, 
            IList<Favorites> databaseRecipes, 
            Menus databaseMenu, 
            ISession session)
        {
            var existing = from r in databaseRecipes select r.Recipe.RecipeId;
            recipesAdd = recipesAdd.Except(existing).ToArray(); // Remove duplicates

            foreach (var recipeId in recipesAdd)
            {
                var fav = new Favorites
                              {
                                  UserId = identity.UserId,
                                  Recipe = new Recipes { RecipeId = recipeId },
                                  Menu = databaseMenu
                              };

                session.Save(fav);
            }
        }
开发者ID:Team-Makev-High-Quality-Code,项目名称:TEAM--MAKEB--High-Quality-Code-Team-Project,代码行数:22,代码来源:DatabaseAdapter.cs

示例3: UpdateMenu

        /// <summary>
        /// Updates a specified menu owned by the current user.
        /// </summary>
        /// <param name="menuId">The Menu ID to update, or null to update the Favorites menu.</param>
        /// <param name="recipesAdd">A list of recipe IDs to add to the menu.  Duplicates will be ignored.</param>
        /// <param name="recipesRemove">A list of recipe IDs to remove from the menu.</param>
        /// <param name="recipesMove">A list of items to move from this menu to another menu.</param>
        /// <param name="clear">If true, all recipes will be removed from this menu.</param>
        /// <param name="newName">An optional new name for this menu.  Note, the favorites menu cannot be renamed.</param>
        /// <returns></returns>
        public MenuResult UpdateMenu(Guid? menuId, Guid[] recipesAdd, Guid[] recipesRemove, MenuMove[] recipesMove, bool clear, string newName = null)
        {
            var ret = new MenuResult();
             ret.IsMenuUpdated = true; // TODO: Verify actual changes were made before setting MenuUpdated to true

             Menus dbMenu = null;
             if (menuId.HasValue)
             {
            dbMenu = store.Menus.SingleOrDefault(p => p.MenuId == menuId);
            if (dbMenu == null)
               throw new MenuNotFoundException();

            if (dbMenu.UserId != Identity.UserId) // User does not have access to modify this menu
               throw new UserDoesNotOwnMenuException();
             }

             var dbFavorites = store.Favorites
            .Where(p => p.MenuId == menuId)
            .ToList();

             if (!string.IsNullOrWhiteSpace(newName) && dbMenu != null) // Rename menu
            dbMenu.Title = newName.Trim();

             if (recipesAdd.Any()) // Add recipes to menu
             {
            var existing = dbFavorites.Select(f => f.RecipeId);
            recipesAdd = recipesAdd.Except(existing).ToArray(); //Remove dupes

            foreach (var rid in recipesAdd)
            {
               var fav = new Favorites
               {
                  FavoriteId = Guid.NewGuid(),
                  UserId = Identity.UserId,
                  RecipeId = rid,
                  MenuId = menuId
               };

               store.Favorites.Add(fav);
            }
             }

             if (recipesRemove.Any()) // Remove recipes from menu
             {
            var toDelete = (from r in dbFavorites where recipesRemove.Contains(r.RecipeId) select r);
            toDelete.ForEach(r => store.Favorites.Remove(r));
             }

             if (clear) // Remove every recipe from menu
             {
            store.Favorites.RemoveAll(dbFavorites.Contains);
             }

             if (recipesMove.Any()) // Move items to another menu
             {
            foreach (var moveAction in recipesMove)
            {
               Menus dbTarget = null;
               if (moveAction.TargetMenu.HasValue)
               {
                  dbTarget = store.Menus
                     .Where(p => p.UserId == Identity.UserId)
                     .SingleOrDefault(p => p.MenuId == moveAction.TargetMenu);

                  if (dbTarget == null)
                     throw new MenuNotFoundException(moveAction.TargetMenu.Value);
               }

               var rToMove = (moveAction.AllMoved
                  ? dbFavorites
                  : dbFavorites.Where(r => moveAction.RecipesToMove.Contains(r.RecipeId)));

               rToMove.ForEach(a => a.MenuId = dbTarget != null ? (Guid?) dbTarget.MenuId : null);
            }
             }

             return ret;
        }
开发者ID:KaloyanTodorov,项目名称:Teamwork,代码行数:88,代码来源:StaticContext.cs

示例4: SetRoleFunctions

 /// <summary>
 /// 设置角色功能
 /// </summary>
 /// <param name="roleId">角色Id</param>
 /// <param name="functionIds">功能Id集合</param>
 /// <returns>业务操作结果</returns>
 public async Task<OperationResult> SetRoleFunctions(int roleId, Guid[] functionIds)
 {
     SysRole role = await RoleRepository.GetByKeyAsync(roleId);
     if (role == null)
     {
         return new OperationResult(OperationResultType.QueryNull, "指定编号的角色信息不存在");
     }
     Guid[] existIds = FunctionRoleMapRepository.Entities.Where(m => m.Role.Id == roleId).Select(m => m.Function.Id).ToArray();
     Guid[] addIds = functionIds.Except(existIds).ToArray();
     Guid[] removeIds = existIds.Except(functionIds).ToArray();
     FunctionRoleMapRepository.UnitOfWork.TransactionEnabled = true;
     foreach (Guid addId in addIds)
     {
         Function function = await FunctionRepository.GetByKeyAsync(addId);
         if (function == null)
         {
             return new OperationResult(OperationResultType.QueryNull, "指定编号的功能信息不存在");
         }
         FunctionRoleMap map = new FunctionRoleMap() { Function = function, Role = role, BeginTime = DateTime.Now };
         await FunctionRoleMapRepository.InsertAsync(map);
     }
     await FunctionRoleMapRepository.DeleteAsync(m => m.Role.Id == roleId && removeIds.Contains(m.Function.Id));
     return await FunctionRoleMapRepository.UnitOfWork.SaveChangesAsync() > 0
         ? new OperationResult(OperationResultType.Success, "角色“{0}”指派功能操作成功".FormatWith(role.Name))
         : OperationResult.NoChanged;
 }
开发者ID:wx5050520,项目名称:Bode,代码行数:32,代码来源:SecurityService.Function.cs


注:本文中的System.Guid.Except方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。