public async Task <ActionResult> Create([Bind(Include = "Title, Description, Phone")] Photo photo, HttpPostedFileBase imageFile)
        {
            CloudBlockBlob imageBlob = null;

            if (ModelState.IsValid)
            {
                if (imageFile != null && imageFile.ContentLength != 0)
                {
                    imageBlob = await UploadAndSaveBlobAsync(imageFile);

                    photo.ImageURL = imageBlob.Uri.ToString();
                }
                photo.PostedDate = DateTime.Now;
                db.Photos.Add(photo);
                await db.SaveChangesAsync();

                Trace.TraceInformation("Created PhotoId {0} in database", photo.PhotoId);

                if (imageBlob != null)
                {
                    var queueMessage = new CloudQueueMessage(photo.PhotoId.ToString());
                    await imagesQueue.AddMessageAsync(queueMessage);

                    Trace.TraceInformation("Created queue message for PhotoId {0}", photo.PhotoId);
                }
                return(RedirectToAction("Index"));
            }

            return(View(photo));
        }
示例#2
0
        /// <summary>
        /// Remove a clien't profile
        /// </summary>
        /// <param name="item">a clien't profile entity</param>
        /// <returns></returns>
        public async Task Remove(ClientProfile item)
        {
            await Task.Run(() => _database.ClientProfiles.Remove(item));

            await _database.SaveChangesAsync();
        }
 public async Task SaveASync()
 {
     await db.SaveChangesAsync();
 }