public static TrashBag BagThis(GenericContent node)
{
var bin = TrashBin.Instance;
if (bin == null)
return null;
if (node == null)
throw new ArgumentNullException("node");
//creating a bag has nothing to do with user permissions: Move will handle that
TrashBag bag = null;
using (new SystemAccount())
{
bag = new TrashBag(bin)
{
KeepUntil = DateTime.Now.AddDays(bin.MinRetentionTime),
OriginalPath = RepositoryPath.GetParentPath(node.Path),
DisplayName = node.DisplayName,
Link = node
};
bag.Save();
CopyPermissions(node, bag);
//add delete permission for the owner
//bag.Security.SetPermission(User.Current, true, PermissionType.Delete, PermissionValue.Allow);
}
try
{
Node.Move(node.Path, bag.Path);
}
catch(Exception ex)
{
Logger.WriteException(ex);
bag.Destroy();
throw new InvalidOperationException("Error moving item to the trash", ex);
}
return bag;
}