public ActionResult GetData(tbl_book model) { tbl_book obj = new tbl_book(); ModelState.Remove("ID"); if (ModelState.IsValid) { obj.ID = model.ID; obj.Title = model.Title; obj.Author = model.Author; obj.ISBN = model.ISBN; obj.Publisher = model.Publisher; obj.Year = model.Year; if (model.ID == 0) { dbobj.tbl_book.Add(obj); dbobj.SaveChanges(); } else { dbobj.Entry(obj).State = EntityState.Modified; dbobj.SaveChanges(); } } ModelState.Clear(); return(View("Book")); }
public ActionResult Create(tbl_book book, string Name, int Page, string Context, HttpPostedFileBase pdf, HttpPostedFileBase image) { if (ModelState.IsValid) { //tbl_book book = new tbl_book(); tbl_photo photo = new tbl_photo(); book.Name = Name; book.Page = Page; book.Context = Context; if (pdf != null && pdf.ContentLength > 0) { string bookName = Guid.NewGuid().ToString().Replace("-", ""); string bookExtension = Path.GetExtension(Request.Files[0].FileName); string bookWay = "/Upload/book/" + bookName + bookExtension; Request.Files[0].SaveAs(Server.MapPath(bookWay)); book.Fileurl = bookWay; db.SaveChanges(); } if (image != null) { string imageName = Guid.NewGuid().ToString().Replace("-", ""); string imageExtension = Path.GetExtension(Request.Files[0].FileName); string imageWay = "/Upload/book/" + imageName + imageExtension; Request.Files[0].SaveAs(Server.MapPath(imageWay)); photo.URL = imageWay; var copyImage = db.tbl_photo.Add(photo); book.PhotoId = copyImage.PhotoId; } db.tbl_book.Add(book); db.SaveChanges(); } return(RedirectToAction("Index")); }
protected void btnAdd_Click(object sender, EventArgs e) { LibrarayManagementSystemEntities1 libEntity = new LibrarayManagementSystemEntities1(); tbl_book book = new tbl_book(); book.BookName = txtBookName.Text; book.Author = txtAuthor.Text; book.Publication = txtPublication.Text; book.Subject = txtSubject.Text; book.NoOfCopies = Convert.ToInt32(txtQuantity.Text); libEntity.AddTotbl_book(book); libEntity.SaveChanges(); lblMessage.Text = "Book Add Successfulyl !"; }
public ActionResult Edit(tbl_book book, int?writerId, int id, string Name, int?Page, string Context, HttpPostedFileBase pdf, HttpPostedFileBase image) { tbl_photo photo = new tbl_photo(); var selectedBook = db.tbl_book.SingleOrDefault(x => x.BookId == id); var writer = db.tbl_Writer.FirstOrDefault(x => x.WriterId == writerId).WriterId; selectedBook.tbl_Writer.WriterId = writer; if (image != null) { if (System.IO.File.Exists(Server.MapPath(selectedBook.tbl_photo.URL))) { System.IO.File.Delete(Server.MapPath(selectedBook.tbl_photo.URL)); } string pictureName = Guid.NewGuid().ToString().Replace("-", ""); string pictureExtension = Path.GetExtension(Request.Files[0].FileName); string pictureWay = "/Upload/images/" + pictureName + pictureExtension; Request.Files[0].SaveAs(Server.MapPath(pictureWay)); photo.URL = pictureWay; var imagecopy = db.tbl_photo.Add(photo); selectedBook.PhotoId = imagecopy.PhotoId; db.SaveChanges(); } if (pdf != null) { if (System.IO.File.Exists(Server.MapPath(selectedBook.Fileurl))) { System.IO.File.Delete(Server.MapPath(selectedBook.Fileurl)); } string fileName = Guid.NewGuid().ToString().Replace("-", ""); string fileExtension = Path.GetExtension(Request.Files[0].FileName); string fileWay = "/Upload/book/" + fileName + fileExtension; Request.Files[0].SaveAs(Server.MapPath(fileWay)); selectedBook.Fileurl = fileWay; db.SaveChanges(); } selectedBook.Name = Name; selectedBook.Page = Page; selectedBook.Context = Context; db.Entry(book).State = EntityState.Detached; db.SaveChanges(); return(RedirectToAction("Index")); }
//public JsonResult Search( string tags) //{ // List<tbl_book> li = dbobj.tbl_book.OrderBy(x => x.ID).ToList(); // return Json(li, JsonRequestBehavior.AllowGet); //} public ActionResult Book(tbl_book obj) { return(View()); }
public static tbl_book Createtbl_book(int id) { tbl_book tbl_book = new tbl_book(); tbl_book.ID = id; return tbl_book; }
public void AddTotbl_book(tbl_book tbl_book) { base.AddObject("tbl_book", tbl_book); }
public ActionResult Addbook(tbl_book b) { return(View()); }
public ActionResult purchase(int id, tbl_order order, tbl_book book) { var tb = db.tbl_book.Where(x => x.b_id == book.b_id).SingleOrDefault(); return(View()); }