private static async Task <string> StoreEventImageInBlobStorage( Binder binder, ILogger log, DownloadEventImageModel eventImageModel) { Uri uri = new Uri(eventImageModel.ImageUrl); var filename = Path.GetFileName(uri.LocalPath); var downloadLocationForEventImage = $"eventimages/{eventImageModel.Id}/{filename}"; using (var blobBinding = await binder.BindAsync <Stream>( new Attribute[] { new BlobAttribute(downloadLocationForEventImage, FileAccess.Write), new StorageAccountAttribute("StorageAccountConnectionString") })) { var webClient = new WebClient(); var imageBytes = await webClient.DownloadDataTaskAsync(uri); log.LogInformation($"Writing event image for CFP `{eventImageModel.Id}` to location `{downloadLocationForEventImage}`."); await blobBinding.WriteAsync(imageBytes, 0, imageBytes.Length); return(downloadLocationForEventImage); } }
private static void UpdateRecordInTheCfpRepository( DownloadEventImageModel eventImageModel, string relativeLocationOfStoredImage, ILogger log) { var storageAccountName = GetEnvironmentVariable("StorageAccountName"); var absoluteImageLocation = $"https://{storageAccountName}.blob.core.windows.net/{relativeLocationOfStoredImage}"; var connectionstring = GetEnvironmentVariable("CfpExchangeDb"); log.LogInformation($"Updating the record `{eventImageModel.Id}` with the event image url to `{absoluteImageLocation}`."); using (var connection = new SqlConnection(connectionstring)) { var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "UPDATE dbo.Cfps SET EventImage = @EventImage WHERE Id = @Id"; command.Parameters.AddWithValue("EventImage", absoluteImageLocation); command.Parameters.AddWithValue("Id", eventImageModel.Id); connection.Open(); command.ExecuteNonQuery(); log.LogInformation($"Updated the record `{eventImageModel.Id}` with the event image url to `{absoluteImageLocation}`."); } }