public ActionResult Edit([Bind(Include = "Id,Title,Price,AuthorId")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AuthorId = new SelectList(db.Authors, "Id", "Name", book.AuthorId);
     return(View(book));
 }
Exemple #2
0
        public async Task <ActionResult> Edit(Book book, HttpPostedFileBase imagefile)
        {
            if (ModelState.IsValid)
            {
                book.rowguid = Guid.NewGuid();
                //Replace local storage with Blob storage to update images universally
                //App configuration settings
                //CloudStorageAccount account = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"];
                //var blobClient = account.CreateCloudBlobClient();
                //var rootContainer = blobClient.GetRootContainerReference();
                //await rootContainer.CreateIfNotExistsAsync();
                //await rootContainer.SetPermissionsAsync(new BlobContainerPermissions {PublicAccess = BlobContainerPublicAccessTy...}
                //var blob = rootContainer.GetBlockBlobReference(imagefile.FileName);
                //await blob.UploadFromStreamAsync....

                imagefile.SaveAs(Server.MapPath("/Images/" + imagefile.FileName));
                book.CoverImage      = "/Images/" + imagefile.FileName;
                db.Entry(book).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(book));
        }