public ActionResult Create([Bind(Include = "Code,New,Name,Price,Pages,Date,Pressrun,izd_id,format_id,themes_id,kategory_id")] books_new books_new) { if (ModelState.IsValid) { books_new.N = db.books_new.Select(b => b.N).Max() + 1; db.books_new.Add(books_new); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.format_id = new SelectList(db.Spr_format, "id", "Format", books_new.format_id); ViewBag.izd_id = new SelectList(db.Spr_izd, "id", "Izd", books_new.izd_id); ViewBag.kategory_id = new SelectList(db.Spr_kategory, "Id", "Category", books_new.kategory_id); ViewBag.themes_id = new SelectList(db.Spr_themes, "id", "Themes", books_new.themes_id); return(View(books_new)); }
public static void addBook(SACH book, List <string> matheloai, List <string> TACGIA, string maNXB) { book.NGAY_BAN = System.DateTime.Now; using (var db = new booksEntities()) { foreach (string mtl in matheloai) { THE_LOAI tl = db.THE_LOAI.Where(theloai => theloai.MA_THE_LOAI == mtl).Select(theloai => theloai).FirstOrDefault(); tl.SACH.Add(book); } NHA_XUAT_BAN nxb = db.NHA_XUAT_BAN.Where(nxban => nxban.MA_NXB == maNXB).Select(nxban => nxban).FirstOrDefault(); nxb.SACH.Add(book); foreach (string tacgia in TACGIA) { TAC_GIA tg = db.TAC_GIA.Where(au => au.TEN_TAC_GIA.Contains(tacgia.Trim())).Select(tgia => tgia).FirstOrDefault(); if (tg == null) { addAuthor(tacgia.Trim()); tg = db.TAC_GIA.Where(au => au.TEN_TAC_GIA.Contains(tacgia.Trim())).Select(tgia => tgia).FirstOrDefault(); } tg.SACH.Add(book); } book.DANH_GIA_TOT = book.TONG_DANH_GIA = 0; db.SACH.Add(book); db.SaveChanges(); } }
public static void addAuthor(string tenTacGia) { TAC_GIA tacgia = new TAC_GIA(); tacgia.TEN_TAC_GIA = tenTacGia; using (var db = new booksEntities()) { db.TAC_GIA.Add(tacgia); db.SaveChanges(); } }
public static void addComment(int maSach, string Noidung) { using (var db = new booksEntities()) { Y_KIEN cmt = new Y_KIEN(); cmt.NOI_DUNG = Noidung; cmt.MA_SACH = maSach; cmt.NGAY = System.DateTime.Now; XtractModule xtract = new XtractModule(); cmt.DANH_GIA = xtract.getEvaluate(Noidung); var book = db.SACH.Where(s => s.MA_SACH == maSach).FirstOrDefault(); book.TONG_DANH_GIA += 1; book.DANH_GIA_TOT += cmt.DANH_GIA.Equals("tích cực") ? 1 : 0; db.Y_KIEN.Add(cmt); db.SaveChanges(); } }
public static void UpdateBook(BookDetails bookdetails) { if (bookdetails == null) { return; } using (var db = new booksEntities()) { for (int index = 0; index < bookdetails.tg.Count; index++) { TAC_GIA tacgia = bookdetails.tg[index]; bookdetails.tg[index] = db.TAC_GIA.Where(x => x.TEN_TAC_GIA == tacgia.TEN_TAC_GIA).FirstOrDefault(); if (bookdetails.tg[index] == null) { addAuthor(tacgia.TEN_TAC_GIA.Trim()); bookdetails.tg[index] = db.TAC_GIA.Where(au => au.TEN_TAC_GIA.Contains(tacgia.TEN_TAC_GIA.Trim())).Select(tgia => tgia).FirstOrDefault(); } } for (int index = 0; index < bookdetails.tl.Count; index++) { THE_LOAI theloai = bookdetails.tl[index]; theloai = db.THE_LOAI.Where(x => x.MA_THE_LOAI == theloai.MA_THE_LOAI).FirstOrDefault(); bookdetails.tl[index] = theloai; } string manxb = bookdetails.nxb.MA_NXB; bookdetails.nxb = db.NHA_XUAT_BAN.Where(x => x.MA_NXB == manxb).FirstOrDefault(); var query = db.SACH.Where(x => x.MA_SACH == bookdetails.sach.MA_SACH).Select(x => x).FirstOrDefault(); var bookAuthor = db.SACH.Include("TAC_GIA"); var bookCate = db.SACH.Include("THE_LOAI"); if (query != null) { query.TEN_SACH = bookdetails.sach.TEN_SACH; query.NOI_DUNG = bookdetails.sach.NOI_DUNG; query.GIA = bookdetails.sach.GIA; if (bookdetails.sach.ANH != null) { query.ANH = bookdetails.sach.ANH; } if (query.TAC_GIA != bookdetails.tg) { foreach (TAC_GIA au in query.TAC_GIA) { au.SACH.Remove(query); } foreach (TAC_GIA au in bookdetails.tg) { au.SACH.Add(query); } } if (query.THE_LOAI != bookdetails.tl) { foreach (THE_LOAI cate in query.THE_LOAI) { cate.SACH.Remove(query); } foreach (THE_LOAI cate in bookdetails.tl) { cate.SACH.Add(query); } } db.SaveChanges(); } } }