public async Task <ActionResult> Edit([Bind(Include = "BookID,Title,AuthorID,CountryID,Price,Description,PagesCount,Picture")] Book book, HttpPostedFileBase image1)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (image1 != null)
                    {
                        FileInfo file     = new FileInfo(image1.FileName);
                        var      fileName = Path.GetFileName(image1.FileName);
                        string   GuIdName = Guid.NewGuid().ToString() + file.Extension;
                        var      path     = Path.Combine(Server.MapPath("~/Picture/"), GuIdName);
                        book.Picture = GuIdName;
                        image1.SaveAs(path);
                    }
                    else
                    {
                        using (BookStoreDatabaseEntities db1 = new BookStoreDatabaseEntities())
                        {
                            var img = db1.Books.Find(book.BookID).Picture;
                            book.Picture = img;
                        }
                    }
                    //if (image1!=null)
                    //{
                    //    book.Picture = new byte[image1.ContentLength];
                    //    image1.InputStream.Read(book.Picture, 0, image1.ContentLength);

                    //}
                    //if (image1==null)
                    //{
                    //    using (BookStoreDatabaseEntities db1 = new BookStoreDatabaseEntities())
                    //    {
                    //        var img = db1.Books.Find(book.BookID).Picture;
                    //        book.Picture = img;
                    //    }
                    //}
                    db.Entry(book).State = EntityState.Modified;
                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                ViewBag.AuthorID  = new SelectList(db.Authors, "AuthorID", "FullName", book.AuthorID);
                ViewBag.CountryID = new SelectList(db.Countries, "CountryID", "CountryName", book.CountryID);
                return(View(book));
            }
            catch
            {
                return(PartialView("Error404"));
            }
        }
 public JsonResult getAll()
 {
     using (BookStoreDatabaseEntities dataContext = new BookStoreDatabaseEntities())
     {
         var bookList = (from E in dataContext.Books
                         join dep in dataContext.Authors on E.AuthorID equals dep.AuthorID
                         join dsg in dataContext.Countries on E.CountryID equals dsg.CountryID
                         orderby E.BookID
                         select new
         {
             E.Country.Tel_Code,
             E.Title,
             E.Price,
             E.BookID,
             E.Picture,
         }).ToList();
         var JsonResult = Json(bookList, JsonRequestBehavior.AllowGet);
         JsonResult.MaxJsonLength = int.MaxValue;
         return(JsonResult);
     }
 }
        public async Task <ActionResult> Edit([Bind(Include = "AuthorID,AuthorName,AuthorLastName,BirthDay,Picture")] Author author, HttpPostedFileBase image1)
        {
            if (ModelState.IsValid)
            {
                if (image1 != null)
                {
                    author.Picture = new byte[image1.ContentLength];
                    image1.InputStream.Read(author.Picture, 0, image1.ContentLength);
                }
                if (image1 == null)
                {
                    using (BookStoreDatabaseEntities db1 = new BookStoreDatabaseEntities())
                    {
                        var img = db1.Authors.Find(author.AuthorID).Picture;
                        author.Picture = img;
                    }
                }
                db.Entry(author).State = EntityState.Modified;
                await db.SaveChangesAsync();

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