/* JSON - ADD CART */ public JsonResult Add_Cart(int id) { if (Session["cart"] == null) { Dictionary <int, Item> list_item = new Dictionary <int, Item>(); list_item.Add(id, new Item { book = BookAction.Find_Book(id), so_luong = 1 }); Session["cart"] = list_item; } else { Dictionary <int, Item> list_item = (Dictionary <int, Item>)Session["cart"]; if (list_item.ContainsKey(id)) { var tmp = list_item[id]; tmp.so_luong = tmp.so_luong + 1; list_item[id] = tmp; } else { list_item.Add(id, new Item { book = BookAction.Find_Book(id), so_luong = 1 }); } } return(Json("Good", JsonRequestBehavior.AllowGet)); }
/* BOOK DETAIL */ public ActionResult BookDetail(int Id) { if (Id != 0) { ViewBag.Book = BookAction.Find_Book(Id); return(View()); } else { return(Redirect("~/Book/ShowBook")); } }
public ActionResult EditBook(int Id) { if ((string)Session["role"] == "admin" || (string)Session["role"] == "staff") { ViewBag.Book = BookAction.Find_Book(Id); ViewBag.Genre = GenreAction.Get_All_Genre(); return(View()); } else { return(Redirect("~/Book/ShowBook")); } }
/* DELETE BOOK */ public ActionResult DeleteBook(int Id) { BookAction.Delete_Book(Id); RecordAction.Create_Record(CustomerAction.Find_Customer((int)Session["id"]).email, CustomerAction.Find_Customer((int)Session["id"]).email + " delete book " + BookAction.Find_Book(Id).ten_sach, DateTime.Now.Date); return(Redirect("~/Book/BookManager/" + Session["id"])); }
/* ------------------------------------------------------------- */ /* UPDATE IMAGE BOOK */ public ActionResult UpdateImg(int Id, HttpPostedFileBase File) { string path = ""; if (File.ContentLength > 0) { string File_Name = Path.GetFileName(File.FileName); path = Path.Combine(Server.MapPath("~/UploadFiles"), File_Name); File.SaveAs(path); BookAction.Update_Img(Id, File_Name); } RecordAction.Create_Record(CustomerAction.Find_Customer((int)Session["id"]).email, CustomerAction.Find_Customer((int)Session["id"]).email + " change image from " + BookAction.Find_Book(Id).ten_sach, DateTime.Now.Date); return(Redirect("~/Book/BookDetail/" + Id)); }
/* Find Book By Name */ public JsonResult FindBook(string name) { return(Json(BookAction.Find_Book(name), JsonRequestBehavior.AllowGet)); }
/* RESTORE BOOKS WERE DELETED */ public ActionResult Unlock_Book(int Id) { BookAction.Restore_Book(Id); RecordAction.Create_Record(CustomerAction.Find_Customer((int)Session["id"]).email, CustomerAction.Find_Customer((int)Session["id"]).email + " restore book " + BookAction.Find_Book(Id).ten_sach, DateTime.Now.Date); return(Redirect("~/Home/RestoreData")); }