DocSas/PropertyService.Domain/ModelView/Media/MediaProvider.cs
/// <summary>
/// upload data as an asynchronous operation.
/// </summary>
/// <param name="options">The options.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
upload data as an asynchronous operation.
upload data as an asynchronous operation .
public async Task<DSCResponse> UploadDataAsync(UploadOptions options)
        {
            var msg = new Dictionary<string, string>();
            var response = new DSCResponse();
            if (options != null && options.Files != null)
            {
                List<UploadFileContent> fileContents = new List<UploadFileContent>();
                StorageRequest storageRequest = new StorageRequest()
                {
                    ConnectionString = await _settingProvider.GetSetting(SettingKey.AzureBlobConnectionString)
                };
                if (options.FileType == PSFileType.image.ToString())
                {
                    storageRequest.ContainerName = options.ContainerName;
                    UploadFileContent fileContent = null;
                    foreach (var file in options.Files)
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            await file.CopyToAsync(memoryStream);
                            fileContent = new UploadFileContent()
                            {
                                HasThumbnail = options.HasThumbnail,
                                MimeType = file.ContentType,
                                FileData = memoryStream.ToArray()
                            };
                                fileContent.FileName = string.Concat(options.DirectoryId, "/", file.FileName);
                                if (fileContent.HasThumbnail)
                                {
                                    fileContent.ThumbnailFileData = Utility.Cropping(fileContent.FileData, options.ThumbnailWidth, options.ThumbnaiHeight);
                                    fileContent.FileThumbnailName = string.Concat(options.DirectoryId, "/", "thumbnail", file.FileName);
                                }
                            fileContents.Add(fileContent);
                         }
                    }
                    storageRequest.UploadFiles = fileContents;
                    var result = await _azureProvider.Save(storageRequest);
                    if (options.UploadType == PSUploadType.CoverImage.ToString())
                    {
                        response = await _propertyProvider.UpdatePropertyImagesAsync(result, options.PropertyInformationId, options.UserId);
                    }
                    else if (options.UploadType == PSUploadType.ProfilePic.ToString())
                    {
                        response = await _userProviderr.UpdateUserProfileImagesAsync(result, options.UserId);
                    }
                }
            }
            response.ErrorMessage = msg;
            return response;
        }
public async Task < DSCResponse > UploadDataAsync ( UploadOptions options ) { var msg = new Dictionary < string , string > ( ) ; var response = new DSCResponse ( ) ; if ( options != null && options . Files != null ) { List < UploadFileContent > fileContents = new List < UploadFileContent > ( ) ; StorageRequest storageRequest = new StorageRequest ( ) { ConnectionString = await _settingProvider . GetSetting ( SettingKey . AzureBlobConnectionString ) } ; if ( options . FileType == PSFileType . image . ToString ( ) ) { storageRequest . ContainerName = options . ContainerName ; UploadFileContent fileContent = null ; foreach ( var file in options . Files ) { using ( var memoryStream = new MemoryStream ( ) ) { await file . CopyToAsync ( memoryStream ) ; fileContent = new UploadFileContent ( ) { HasThumbnail = options . HasThumbnail , MimeType = file . ContentType , FileData = memoryStream . ToArray ( ) } ; fileContent . FileName = string . Concat ( options . DirectoryId , " " , file . FileName ) ; if ( fileContent . HasThumbnail ) { fileContent . ThumbnailFileData = Utility . Cropping ( fileContent . FileData , options . ThumbnailWidth , options . ThumbnaiHeight ) ; fileContent . FileThumbnailName = string . Concat ( options . DirectoryId , " " , " " , file . FileName ) ; } fileContents . Add ( fileContent ) ; } } storageRequest . UploadFiles = fileContents ; var result = await _azureProvider . Save ( storageRequest ) ; if ( options . UploadType == PSUploadType . CoverImage . ToString ( ) ) { response = await _propertyProvider . UpdatePropertyImagesAsync ( result , options . PropertyInformationId , options . UserId ) ; } else if ( options . UploadType == PSUploadType . ProfilePic . ToString ( ) ) { response = await _userProviderr . UpdateUserProfileImagesAsync ( result , options . UserId ) ; } } } response . ErrorMessage = msg ; return response ; }
upload data as an asynchronous operation.
upload data as an asynchronous operation .
None
options
UploadOptions
None