Guest User

Untitled

a guest
Jul 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. [HttpPut]
  2. public async Task<IHttpActionResult> PutTenant([ModelBinder(typeof(TenantModelBinder))] Tenant tenant)
  3. {
  4. //var provider = new MultipartMemoryStreamProvider();
  5. //var contentType = "";
  6. //var content = new byte[0];
  7. //await base.Request.Content.ReadAsMultipartAsync(provider);
  8. //if (provider.Contents.Count > 0)
  9. //{
  10. // contentType = provider.Contents[0].Headers.ContentType.MediaType;
  11. // content = await provider.Contents[0].ReadAsByteArrayAsync();
  12. //}
  13.  
  14.  
  15. CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["AzureStorageKey"].ToString());
  16. // Create the blob client.
  17. CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
  18.  
  19. // Retrieve reference to a previously created container.
  20. CloudBlobContainer container = blobClient.GetContainerReference(ConfigurationManager.AppSettings["certificatesContainer"].ToString());
  21.  
  22. // Retrieve reference to a blob named "myblob".
  23. CloudBlockBlob blockBlob = container.GetBlockBlobReference("myblob");
  24.  
  25. // Create or overwrite the "myblob" blob with contents from a local file.
  26. //blockBlob.Properties.ContentType = tenant.ContentType;
  27. MemoryStream stream = new MemoryStream(tenant.CertificateFile);
  28. blockBlob.UploadFromStream(stream);
  29.  
  30. var tenantStore = CosmosStoreFactory.CreateForEntity<Tenant>();
  31. tenant.CertificatePath = blockBlob.Uri;
  32.  
  33. if (!ModelState.IsValid)
  34. {
  35. return BadRequest(ModelState);
  36. }
  37.  
  38. var added = await tenantStore.AddAsync(tenant);
  39. return StatusCode(HttpStatusCode.NoContent);
  40. }
  41.  
  42. Unable to resolve iD for entity of type Tenant
  43.  
  44. public class Tenant
  45. {
  46. public string TenantId { get; set; }
  47. public string TenantUrl { get; set; }
  48. public Uri CertificatePath { get; set; }
  49. public string CertificatePassword { get; set; }
  50.  
  51. public byte[] CertificateFile { get; set; }
  52.  
  53. public override string ToString()
  54. {
  55. return JsonConvert.SerializeObject(this);
  56. }
  57. }
Add Comment
Please, Sign In to add comment