public ActionResult DeleteConfirmed(int id) { Tbl_Books tbl_Books = db.Tbl_Books.Find(id); db.Tbl_Books.Remove(tbl_Books); db.SaveChanges(); return RedirectToAction("Index"); }
/* public string uploadingpdffile(HttpPostedFileBase file) * { * Random r = new Random(); * string path = "-1"; * int random = r.Next(); * if (file != null && file.ContentLength > 0) * { * string extension = Path.GetExtension(file.FileName); * if (extension.ToLower().Equals(".pdf")) * { * try * { * path = Path.Combine(Server.MapPath("~/Content/pdfbooks/"), random + Path.GetFileName(file.FileName)); * file.SaveAs(path); * path = "~/Content/pdfbooks/" + random + Path.GetFileName(file.FileName); * * } * catch (Exception ex) * { * path = "-1"; * } * } * else * { * Response.Write("<script>alert('only jgp,jpeg or png formats are acceptable .... ';</script>"); * } * } * else * { * Response.Write("<script>alert('Please select a file'); </script>"); * path = "-1"; * } * return path; * } * */ public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Books Tbl_Books = db.Tbl_Books.Find(id); if (Tbl_Books == null) { return(HttpNotFound()); } List <Book_categoryy> li3 = db.Book_categoryy.ToList(); ViewBag.catlist = new SelectList(li3, "cat_id", "cat_name"); List <Tbl_Vendorr> li4 = db.Tbl_Vendorr.ToList(); ViewBag.venlist = new SelectList(li4, "Vendor_id", "Vendor_name"); return(View(Tbl_Books)); }
public ActionResult Create([Bind(Include = "ID,Name,AuthorID,PagesCount,Size,Fi,SubjectID,TranslatorID,Image,CoverType,ISBN,ReleasedDate,PublishedDate,circulation,IsTranslated")] Tbl_Books tbl_Books) { if ( (tbl_Books.Name == null || tbl_Books.Name.Length == 0) || (tbl_Books.Image == null || tbl_Books.Image.Length == 0) || (tbl_Books.ISBN == null || tbl_Books.ISBN == 0) || (tbl_Books.ReleasedDate == null) || (tbl_Books.TranslatorID == null) || (tbl_Books.AuthorID == -1) ) { ViewBag.ErrorMessage = "لطفا مقادیر را درست وارد کنید..."; } else if (ModelState.IsValid) { if (!tbl_Books.IsTranslated) { tbl_Books.TranslatorID = -1; } db.Tbl_Books.Add(tbl_Books); db.SaveChanges(); return(RedirectToAction("Index")); } var AuthorsAndTranslators = db.Tbl_authorsAndTranslators.Select(n => new { ID = n.ID, FullName = n.FName + " " + n.LName }); var LstAuthorsAndTranslators = AuthorsAndTranslators.ToList(); //LstAuthorsAndTranslators.Insert(0, new { ID = 0, FullName = "" }); ViewBag.TranslatorID = ViewBag.AuthorID = new SelectList(LstAuthorsAndTranslators, "ID", "FullName"); //ViewBag.TranslatorID = new SelectList(LstAuthorsAndTranslators, "ID", "FullName"); //new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName"); ViewBag.SubjectID = new SelectList(db.Tbl_BooksCategories, "ID", "Name"); var LstCoverType = db.Tbl_BooksCoverType.ToList(); LstCoverType.Insert(0, new Tbl_BooksCoverType { ID = 0, Name = "" }); ViewBag.CoverType = new SelectList(LstCoverType, "ID", "Name"); var LstBooksSize = db.Tbl_BooksSize.ToList(); LstBooksSize.Insert(0, new Tbl_BooksSize { ID = 0, Name = "" }); ViewBag.Size = new SelectList(LstBooksSize, "ID", "Name"); //ViewBag.AuthorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.AuthorID); //ViewBag.TranslatorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.TranslatorID); //ViewBag.SubjectID = new SelectList(db.Tbl_BooksCategories, "ID", "Name", tbl_Books.SubjectID); //ViewBag.CoverType = new SelectList(db.Tbl_BooksCoverType, "ID", "Name", tbl_Books.CoverType); //ViewBag.Size = new SelectList(db.Tbl_BooksSize, "ID", "Name", tbl_Books.Size); return(View(tbl_Books)); }
// GET: Tbl_Books/Details/5 public ActionResult Details(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Tbl_Books tbl_Books = db.Tbl_Books.Find(id); if (tbl_Books == null) { return HttpNotFound(); } return View(tbl_Books); }
// GET: Tbl_Books/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Books tbl_Books = db.Tbl_Books.Find(id); if (tbl_Books == null) { return(HttpNotFound()); } return(View(tbl_Books)); }
public ActionResult Edit([Bind(Include = "ID,Name,AuthorID,PagesCount,Size,Fi,SubjectID,TranslatorID,Image,CoverType,ISBN,ReleasedDate,PublishedDate,circulation,IsTranslated")] Tbl_Books tbl_Books) { if (ModelState.IsValid) { db.Entry(tbl_Books).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AuthorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.AuthorID); ViewBag.TranslatorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.TranslatorID); ViewBag.SubjectID = new SelectList(db.Tbl_BooksCategories, "ID", "Name", tbl_Books.SubjectID); ViewBag.CoverType = new SelectList(db.Tbl_BooksCoverType, "ID", "Name", tbl_Books.CoverType); ViewBag.Size = new SelectList(db.Tbl_BooksSize, "ID", "Name", tbl_Books.Size); return(View(tbl_Books)); }
// GET: Tbl_Books/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Books tbl_Books = db.Tbl_Books.Find(id); var AuthorsAndTranslators = db.Tbl_authorsAndTranslators.Select(n => new { ID = n.ID, FullName = n.FName + " " + n.LName }); var LstAuthorsAndTranslators = AuthorsAndTranslators.ToList(); LstAuthorsAndTranslators.Insert(0, new { ID = 0, FullName = "" }); ViewBag.TranslatorID = new SelectList(LstAuthorsAndTranslators, "ID", "FullName", tbl_Books.TranslatorID); ViewBag.AuthorID = new SelectList(LstAuthorsAndTranslators, "ID", "FullName", tbl_Books.AuthorID); //ViewBag.TranslatorID = new SelectList(LstAuthorsAndTranslators, "ID", "FullName"); //new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName"); ViewBag.SubjectID = new SelectList(db.Tbl_BooksCategories, "ID", "Name", tbl_Books.SubjectID); var LstCoverType = db.Tbl_BooksCoverType.ToList(); LstCoverType.Insert(0, new Tbl_BooksCoverType { ID = 0, Name = "" }); ViewBag.CoverType = new SelectList(LstCoverType, "ID", "Name", tbl_Books.CoverType); var LstBooksSize = db.Tbl_BooksSize.ToList(); LstBooksSize.Insert(0, new Tbl_BooksSize { ID = 0, Name = "" }); ViewBag.Size = new SelectList(LstBooksSize, "ID", "Name", tbl_Books.Size); if (tbl_Books == null) { return(HttpNotFound()); } //ViewBag.AuthorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.AuthorID); //ViewBag.TranslatorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.TranslatorID); //ViewBag.SubjectID = new SelectList(db.Tbl_BooksCategories, "ID", "Name", tbl_Books.SubjectID); //ViewBag.CoverType = new SelectList(db.Tbl_BooksCoverType, "ID", "Name", tbl_Books.CoverType); //ViewBag.Size = new SelectList(db.Tbl_BooksSize, "ID", "Name", tbl_Books.Size); return(View(tbl_Books)); }
// GET: Tbl_Books/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Tbl_Books tbl_Books = db.Tbl_Books.Find(id); if (tbl_Books == null) { return HttpNotFound(); } ViewBag.AuthorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.AuthorID); ViewBag.TranslatorID = new SelectList(db.Tbl_authorsAndTranslators, "ID", "FName", tbl_Books.TranslatorID); ViewBag.SubjectID = new SelectList(db.Tbl_BooksCategories, "ID", "Name", tbl_Books.SubjectID); ViewBag.CoverType = new SelectList(db.Tbl_BooksCoverType, "ID", "Name", tbl_Books.CoverType); ViewBag.Size = new SelectList(db.Tbl_BooksSize, "ID", "Name", tbl_Books.Size); return View(tbl_Books); }
public ActionResult addtocart(Tbl_Books book, string qty, int id) { Tbl_Books b1 = db.Tbl_Books.Where(x => x.Book_id == id).SingleOrDefault(); cart c = new cart(); c.Book_id = b1.Book_id; c.Book_name = b1.Book_name; c.Book_price = (float)b1.Book_price; c.qty = Convert.ToInt32(qty); c.bill = c.Book_price * c.qty; if (TempData["cart"] == null) { li.Add(c); TempData["cart"] = li; } else { List <cart> li2 = TempData["cart"] as List <cart>; int flag = 0; foreach (var item in li2) { if (item.Book_id == c.Book_id) { item.qty += c.qty; item.bill += c.bill; flag = 1; } } if (flag == 0) { li2.Add(c); } TempData["cart"] = li2; } TempData.Keep(); return(RedirectToAction("Index")); }
//POST: Bookcategoryy/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://go.microsoft.com/fwlink/?LinkId=317598. public ActionResult Edit(Tbl_Books Tbl_Books, HttpPostedFileBase imagefile) { var tbl_Books = db.Tbl_Books.Find(Tbl_Books.Book_id); if (ModelState.IsValid) { if (!string.IsNullOrEmpty(imagefile != null ? imagefile.FileName : "")) { string path = uploadingfile(imagefile); if (path.Equals("-1")) { ViewBag.error = "Image could not be uploaded...."; } else { tbl_Books.Book_img = path; } } tbl_Books.Book_name = Tbl_Books.Book_name; tbl_Books.Book_Edition = Tbl_Books.Book_Edition; tbl_Books.Book_price = Tbl_Books.Book_price; tbl_Books.auth_id = Tbl_Books.auth_id; tbl_Books.pub_id = Tbl_Books.pub_id; tbl_Books.cat_id = Tbl_Books.cat_id; db.Entry(tbl_Books).State = EntityState.Modified; db.SaveChanges(); if (Session["Admin_id"] != null) { return(RedirectToAction("AdminIndex")); } else { return(RedirectToAction("Index")); } } return(View(Tbl_Books)); }
public ActionResult Create(Tbl_for_books evm, HttpPostedFileBase imagefile, HttpPostedFileBase pdffile) { // string path1 = uploadingpdffile(pdffile); string path = uploadingfile(imagefile); if (path.Equals("-1")) { ViewBag.error = "Image could not be uploaded...."; } else { //List<Book_author> li = db.Book_author.ToList(); //ViewBag.authlist = new SelectList(li, "auth_id", "auth_name"); //List<Book_publisher> li2 = db.Book_publisher.ToList(); //ViewBag.publist = new SelectList(li2, "pub_id", "pub_name"); List <Book_categoryy> li3 = db.Book_categoryy.ToList(); ViewBag.catlist = new SelectList(li3, "cat_id", "cat_name"); List <Tbl_Vendorr> li4 = db.Tbl_Vendorr.ToList(); ViewBag.venlist = new SelectList(li4, "Vendor_id", "Vendor_name"); Tbl_Books bk = new Tbl_Books(); bk.Book_name = evm.Book_name; bk.Book_img = path; bk.auth_id = evm.auth_id; bk.pub_id = evm.pub_id; bk.cat_id = evm.cat_id; bk.Book_Edition = evm.Book_Edition; bk.Book_price = evm.Book_price; bk.Vendor_id = evm.Vendor_id; // bk.Book_ebook = path1; db.Tbl_Books.Add(bk); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public ActionResult addtocart(int?id) { Tbl_Books book = db.Tbl_Books.Where(x => x.Book_id == id).SingleOrDefault(); return(View(book)); }