/// <summary>
 /// Check if there are same names at the same tree level
 /// </summary>
 /// <param name="tree"></param>
 /// <returns></returns>
 private void CheckSameName(TTree tree)
 {
     if (_generalTreeRepository.GetAll().Where(EqualParentId(tree.ParentId))
         .WhereIf(_generalTreeConfiguration.CheckSameNameExpression != null,
                  x => _generalTreeConfiguration.CheckSameNameExpression(x, tree))
         .Where(NotEqualId(tree.Id))
         .Any(x => x.Name == tree.Name))
     {
         throw new UserFriendlyException(_generalTreeConfiguration.ExceptionMessageFactory.Invoke(tree));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Check if there are same names at the same tree level
        /// </summary>
        /// <param name="tree"></param>
        /// <returns></returns>
        private void CheckSameName(TTree tree)
        {
            if (_generalTreeConfiguration.CheckSameNameExpression == null)
            {
                if (!_generalTreeRepository.GetAll().Where(EqualParentId(tree.ParentId))
                    .Where(NotEqualId(tree.Id))
                    .Any(x => x.Name == tree.Name))
                {
                    return;
                }
            }
            else
            {
                var trees = _generalTreeRepository.GetAll().Where(EqualParentId(tree.ParentId))
                            .Where(NotEqualId(tree.Id))
                            .Where(x => x.Name == tree.Name).ToList();
                if (!trees.Any() || !trees.Any(x => _generalTreeConfiguration.CheckSameNameExpression(x, tree)))
                {
                    return;
                }
            }

            throw new UserFriendlyException(_generalTreeConfiguration.ExceptionMessageFactory.Invoke(tree));
        }