public async Task RenameAsync(IUserCategory category, TaskContext context)
        {
            var authentication = context.Authentication;
            var categoryName   = RandomUtility.NextIdentifier();

            if (context.AllowException == false)
            {
                if (await category.Dispatcher.InvokeAsync(() => category.Parent) == null)
                {
                    return;
                }
            }
            await category.RenameAsync(authentication, categoryName);
        }
Beispiel #2
0
        private async Task MoveUserCategoryAsync(Authentication authentication, IUserCategory sourceCategory, string destPath)
        {
            var destObject = await this.GetObjectAsync(destPath);

            //var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase;
            var users = sourceCategory.GetService(typeof(IUserCollection)) as IUserCollection;

            //if (destPath.DataBaseName != dataBase.Name)
            //    throw new InvalidOperationException($"cannot move to : {destPath}");
            //if (destPath.Context != CremaSchema.UserDirectory)
            //    throw new InvalidOperationException($"cannot move to : {destPath}");
            if (destObject is IUser)
            {
                throw new InvalidOperationException($"cannot move to : {destPath}");
            }

            if (destObject is IUserCategory destCategory)
            {
                if (sourceCategory.Parent != destCategory)
                {
                    await sourceCategory.MoveAsync(authentication, destCategory.Path);
                }
            }
            else
            {
                if (NameValidator.VerifyCategoryPath(destPath) == true)
                {
                    throw new InvalidOperationException($"cannot move to : {destPath}");
                }
                var itemName   = new ItemName(destPath);
                var categories = sourceCategory.GetService(typeof(IUserCategoryCollection)) as IUserCategoryCollection;
                if (await categories.ContainsAsync(itemName.CategoryPath) == false)
                {
                    throw new InvalidOperationException($"cannot move to : {destPath}");
                }
                if (sourceCategory.Name != itemName.Name && await users.ContainsAsync(itemName.Name) == true)
                {
                    throw new InvalidOperationException($"cannot move to : {destPath}");
                }
                if (sourceCategory.Parent.Path != itemName.CategoryPath)
                {
                    await sourceCategory.MoveAsync(authentication, itemName.CategoryPath);
                }
                if (sourceCategory.Name != itemName.Name)
                {
                    await sourceCategory.RenameAsync(authentication, itemName.Name);
                }
            }
        }