public async Task <IActionResult> RemovePendingUploads(string ids) { var user = GetUser(); var pendingUploadFiles = await _filesStorageProvider.GetFiles(user.PendingUploadPhotosFolderName); if (!pendingUploadFiles.Any()) { return(BadRequest("Attempt to remove pending uploads failed because there are no pending uploads")); } var pendingUploadsToRemoveIds = ids.Split(',', StringSplitOptions.RemoveEmptyEntries); var pendingUploadsToRemove = pendingUploadFiles.Select(x => x.FileId) .Intersect(pendingUploadsToRemoveIds.AsEnumerable()).ToList(); if (!pendingUploadsToRemove.Any()) { return(BadRequest("Attempt to remove pending uploads failed because of wrong passed ids")); } if (pendingUploadsToRemoveIds.AsEnumerable().Except(pendingUploadFiles.Select(x => x.FileId)).Any()) { return(BadRequest("Attempt to remove pending uploads failed because there are some not existing id in passed ids")); } await Task.Run(() => pendingUploadsToRemove.ForEach(fileId => { _filesStorageProvider.Remove(fileId, user.PendingUploadPhotosFolderName); _photoService.RemovePhoto(user.Id, fileId); })); return(NoContent()); }
public async Task Handle(PhotoUploadedNotificationEvent notification, CancellationToken cancellationToken) { var user = await _userService.GetUser(notification.UserId); var downloadResult = await _filesStorageProvider.DownloadAsync(notification.FileId, user.PendingUploadPhotosFolderName); var imageUploadResult = await _photoStorageProvider.Upload(notification.FileId, downloadResult.FileStream); var photoForUser = new PhotoForUserDto { FileId = notification.FileId, PublicId = imageUploadResult.PublicId, UserId = notification.UserId, Url = imageUploadResult.Uri, Title = notification.Title, Subtitle = notification.Subtitle, Description = notification.Description }; await _photoService.UpdatePhotoForUser(photoForUser); await _filesStorageProvider.Remove(notification.FileId, user.PendingUploadPhotosFolderName); }