public async Task <NodeEntry> ShreddingProposalCreate(string name, List <string> ids) { var nodes = new List <NodeEntry>(); await ids.ForEachAsync(async x => { #region Validations var nodeInfo = await _alfrescoHttpClient.GetNodeInfo(x); nodes.Add(nodeInfo); var properties = nodeInfo.Entry.Properties.As <JObject>().ToDictionary(); var discardReason = properties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardReason)?.ToString(); var discardTo = properties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardTo)?.ToString(); var discardDate = properties.GetNestedValueOrDefault(SpisumNames.Properties.DiscardDate)?.ToString(); var borrower = properties.GetNestedValueOrDefault(SpisumNames.Properties.Borrower)?.ToString(); var proposalName = properties.GetNestedValueOrDefault(SpisumNames.Properties.ProposalName)?.ToString(); if (!string.IsNullOrWhiteSpace(proposalName)) { throw new BadRequestException("", "One or more of the ids cannot be used because they were used previously."); } var parentRm = await _nodesService.GetParentsByAssociation(x, new List <string> { SpisumNames.Associations.DocumentInRepository, SpisumNames.Associations.FileInRepository }); var rmRef = parentRm.FirstOrDefault()?.Entry?.Id; if (string.IsNullOrWhiteSpace(rmRef)) { throw new BadRequestException("", "One or more of the ids are not in record management."); } var rmNodeInfo = await _alfrescoHttpClient.GetNodeInfo(rmRef); var propertiesRm = rmNodeInfo.Entry.Properties.As <JObject>().ToDictionary(); var cutOffDate = propertiesRm.GetNestedValueOrDefault(AlfrescoNames.ContentModel.CutOffDate)?.ToString(); if (string.IsNullOrWhiteSpace(cutOffDate)) { throw new BadRequestException("", "One or more of the ids has not been cut off yet."); } if (!string.IsNullOrWhiteSpace(discardReason) || !string.IsNullOrWhiteSpace(discardTo) || !string.IsNullOrWhiteSpace(discardDate) || !string.IsNullOrWhiteSpace(borrower)) { throw new BadRequestException("", "One or more of ids is borrowed or removed of shredding plan"); } #endregion }); var shreddingPlanCreate = await _alfrescoHttpClient.CreateNode(AlfrescoNames.Aliases.Root, new FormDataParam(new byte[] { 01 }), ImmutableList <Parameter> .Empty .Add(new Parameter(AlfrescoNames.Headers.NodeType, SpisumNames.NodeTypes.ShreddingProposal, ParameterType.GetOrPost)) .Add(new Parameter(AlfrescoNames.Headers.Name, IdGenerator.GenerateId(), ParameterType.GetOrPost)) .Add(new Parameter(AlfrescoNames.Headers.RelativePath, SpisumNames.Paths.RepositoryShreddingProposal, ParameterType.GetOrPost)) .Add(new Parameter(AlfrescoNames.Headers.Include, AlfrescoNames.Includes.Properties, ParameterType.QueryString)) .Add(new Parameter(SpisumNames.Properties.Name, name, ParameterType.GetOrPost)) .Add(new Parameter(SpisumNames.Properties.AssociationCount, nodes.Count, ParameterType.GetOrPost)) .Add(new Parameter(SpisumNames.Properties.CreatedDate, DateTime.UtcNow.ToAlfrescoDateTimeString(), ParameterType.GetOrPost)) .Add(new Parameter(SpisumNames.Properties.Author, _identityUser.Id, ParameterType.GetOrPost)) ); var shreddingPlan = await _alfrescoHttpClient.GetNodeInfo(shreddingPlanCreate?.Entry?.Id); var shredding = shreddingPlan?.Entry?.Properties.As <JObject>().ToDictionary(); var pid = shredding.GetNestedValueOrDefault(SpisumNames.Properties.Pid)?.ToString(); await nodes.ForEachAsync(async x => { await _nodesService.TryUnlockNode(x?.Entry?.Id); await _alfrescoHttpClient.CreateNodeSecondaryChildren(shreddingPlan?.Entry?.Id, new ChildAssociationBody { AssocType = SpisumNames.Associations.ShreddingObjects, ChildId = x?.Entry?.Id }); await _alfrescoHttpClient.UpdateNode(x?.Entry?.Id, new NodeBodyUpdate() .AddProperty(SpisumNames.Properties.ProposalName, pid) ); await _alfrescoHttpClient.NodeLock(x?.Entry?.Id, new NodeBodyLock { Type = NodeBodyLockType.FULL }); }); return(shreddingPlan); }