public async Task <ActionResult> Create( [Bind(Include = "Title,Price,Description,Category,Phone")] Ad ad, HttpPostedFileBase imageFile) { CloudBlockBlob imageBlob = null; // A production app would implement more robust input validation. // For example, validate that the image file size is not too large. if (ModelState.IsValid) { if (imageFile != null && imageFile.ContentLength != 0) { imageBlob = await UploadAndSaveBlobAsync(imageFile); ad.ImageURL = imageBlob.Uri.ToString(); } ad.PostedDate = DateTime.Now; db.Ads.Add(ad); await db.SaveChangesAsync(); Trace.TraceInformation("Created AdId {0} in database", ad.AdId); if (imageBlob != null) { var queueMessage = new CloudQueueMessage(ad.AdId.ToString()); await imagesQueue.AddMessageAsync(queueMessage); Trace.TraceInformation("Created queue message for AdId {0}", ad.AdId); } return(RedirectToAction("Index")); } return(View(ad)); }
//POST: Ad/Create public async Task <ActionResult> Create( [Bind(Include = "Title,Proce,Description,Category,Phone")] Ad ad, HttpPostedFileBase imageFile) { if (ModelState.IsValid) { CloudBlockBlob imageBlob = null; if (imageFile != null && imageFile.ContentLength != 0) { Trace.TraceInformation("Uploading imagefile {0}", imageFile.FileName); imageBlob = await UploadAndSaveBlobAsync(imageFile); ad.ImageURL = imageBlob.Uri.ToString(); } ad.PostedDate = DateTime.Now; db.Ads.Add(ad); await db.SaveChangesAsync(); Trace.TraceInformation("Created AdId {0} in database", ad.AdId); if (imageBlob != null) { Trace.TraceInformation("Creating queue message for AdId {0}", ad.AdId); BlobInformation blobInfo = new BlobInformation { AdId = ad.AdId, BlobUri = imageBlob.Uri }; await thumbmailRequestQueue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(blobInfo))); Trace.TraceInformation("Created queue message for AdId {0}", ad.AdId); } return(RedirectToAction("Index")); } return(View(ad)); }