Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Microsoft.AspNetCore.Mvc.HttpPost, Microsoft.AspNetCore.Mvc.Route("restore/sharepoint/azure-blob-storage/o365")]
- [Authorize(Roles = "O365User,O365Admin,NexeticAdmin")]
- public override Task<bool> PostRestoreSharepointAzureBlobStorageO365([FromQuery] int? userId, [FromQuery] bool? toRestoreFolder, [FromQuery] bool? fromTeams, [FromBody] IEnumerable<int> body)
- {
- VerifyUsersOrganization(userId.Value);
- return TaskUtility.Run<bool>(() =>
- {
- try
- {
- List<int> itemsIds = body.ToList();
- if (userId.HasValue && itemsIds.Count > 0 && fromTeams.HasValue)
- {
- User user = _userService.Get(userId.Value);
- if (user != null)
- {
- List<SharepointListItemVersion> finalList = new List<SharepointListItemVersion>();
- foreach (int itemId in itemsIds)
- {
- SharepointListItemVersion version = _sharePointService.GetListItemVersionById(itemId);
- if (version != null)
- {
- OneDriveItem oneDriveItem = _sharePointService.GetDriveItemBySharePointItemId(version.SharepointListItemId ?? 0);
- if (oneDriveItem != null)
- {
- if (oneDriveItem.IsFolder)
- {
- OneDriveItemVersion oneDriveItemVersion = _sharePointService.GetDriveItemVersionByDriveItemId(oneDriveItem.Id);
- if (oneDriveItemVersion != null)
- {
- List<OneDriveItem> childDriveItems = _driveService.GetByParentPath(oneDriveItemVersion.Path, -1, fromTeams.Value, true);
- if (childDriveItems != null && childDriveItems.Count > 0)
- {
- foreach (OneDriveItem childItem in childDriveItems)
- {
- SharepointListItem toAddItem = _sharePointService.GetSharePointItemByDriveId(childItem.Id);
- if (toAddItem != null)
- {
- SharepointListItemVersion versionToAdd = _sharePointService.GetLastVersionByItemId(toAddItem.Id);
- if (versionToAdd != null)
- {
- if (!finalList.Contains(versionToAdd))
- {
- finalList.Add(versionToAdd);
- }
- }
- }
- }
- }
- }
- }
- else
- {
- if (!finalList.Contains(version))
- {
- finalList.Add(version);
- }
- }
- }
- }
- }
- if (finalList.Count > 0)
- {
- List<string> selectedIds = finalList.Select(x => x.Id + "from" + x.InitialExternalId).ToList();
- _backupRestoreService.RestoreSharePoint(
- user.ExternalServiceOrganizationId,
- toRestoreFolder ?? false,
- selectedIds
- );
- return true;
- }
- }
- }
- return false;
- }
- catch (Exception ex)
- {
- _logger.LogError($"Error initiating sharepoint restore: {ex.ToString()}");
- return false;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment