public IActionResult Index() { List <MuonSachView> la = new List <MuonSachView>(); MuonSachView[] result = new MuonSachView[100]; var Store = DatabaseHelper.store; Store.Initialize(); using (var session = Store.OpenSession()) { List <MuonSachView> li = session.Query <MuonSachView>().ToList <MuonSachView>(); foreach (MuonSachView t in li) { MuonSachView ti = new MuonSachView { Id = t.Id, MaPhieu = t.MaPhieu, TenDG = t.TenDG, TenSach = t.TenSach, TenChiNhanh = t.TenChiNhanh, SoLuongMuon = t.SoLuongMuon, NgayMuon = t.NgayMuon }; la.Add(ti); } } // Send to the Server // one request processed in one transaction return(View(la)); }
//Tìm kiếm public static List <MuonSachView> TimKiemTheoMaPhieu(string p) { List <MuonSachView> phieus = new List <MuonSachView>(); using (IDocumentSession session = store.OpenSession()) // Open a session for a default 'Database' { List <PhieuMuonSachSV> phieu = session .Query <PhieuMuonSachSV>() // Query for Products .Include(x => x.DocGia) .Include(x => x.Sach) .Include(x => x.ChiNhanh) .Where(x => x.MaPhieu == p) // Filter .ToList(); // Materialize query foreach (PhieuMuonSachSV x in phieu) { DocGiaSV dg = session.Load <DocGiaSV>(x.DocGia); ChiNhanh cn = session.Load <ChiNhanh>(x.ChiNhanh); Sach s = session.Load <Sach>(x.Sach); MuonSachView detail = new MuonSachView { MaPhieu = x.MaPhieu, TenDG = dg.TenDG, TenSach = s.TenSach, TenChiNhanh = cn.TenChiNhanh, SoLuongMuon = x.SoLuongMuon, NgayMuon = x.NgayMuon }; phieus.Add(detail); } } return(phieus); }
//Xóa Phiếu không xóa references public IActionResult Delete(string id) { id = id.Replace("*", "/"); //load dữ liệu MuonSachView pms = DatabaseHelper.List(id)[0]; DatabaseHelper.Delete(id); return(View(pms)); }
//Load phiếu public static List <MuonSachView> List(string id) { List <MuonSachView> res = new List <MuonSachView>(); using (IDocumentSession session = store.OpenSession()) { List <PhieuMuonSachSV> sv; if (id != null) { sv = session .Query <PhieuMuonSachSV>() .Where(x => x.Id == id) .Include(x => x.DocGia) .Include(x => x.Sach) .Include(x => x.ChiNhanh) .ToList <PhieuMuonSachSV>(); } else { sv = session .Query <PhieuMuonSachSV>() .Include(x => x.DocGia) .Include(x => x.Sach) .Include(x => x.ChiNhanh) .ToList <PhieuMuonSachSV>(); } foreach (PhieuMuonSachSV pms in sv) { DocGiaSV dg = session.Load <DocGiaSV>(pms.DocGia); ChiNhanh cn = session.Load <ChiNhanh>(pms.ChiNhanh); Sach s = session.Load <Sach>(pms.Sach); MuonSachView detail = new MuonSachView { Id = pms.Id, MaPhieu = pms.MaPhieu, TenDG = dg.TenDG, TenSach = s.TenSach, TenChiNhanh = cn.TenChiNhanh, SoLuongMuon = pms.SoLuongMuon, NgayMuon = pms.NgayMuon }; res.Add(detail); } } return(res); }
//Sửa Phiếu không sửa references public IActionResult Edit([Bind("Id,MaPhieu,TenDG,TenSach,TenChiNhanh,SoLuongMuon,NgayMuon")] MuonSachView pms) { pms.Id = pms.Id.Replace("*", "/"); //Xử lý sửa database PhieuMuonSachSV res = new PhieuMuonSachSV { Id = pms.Id, MaPhieu = pms.MaPhieu, DocGia = pms.TenDG, Sach = pms.TenSach, ChiNhanh = pms.TenChiNhanh, SoLuongMuon = pms.SoLuongMuon, NgayMuon = pms.NgayMuon }; DatabaseHelper.Edit(res); return(View(pms)); }
public IActionResult Add([Bind("MaPhieu,TenDG,TenSach,TenChiNhanh,SoLuongMuon,NgayMuon")] MuonSachView pms) { if (ModelState.IsValid && pms.MaPhieu != null) { PhieuMuonSachSV res = new PhieuMuonSachSV { MaPhieu = pms.MaPhieu, DocGia = pms.TenDG, Sach = pms.TenSach, ChiNhanh = pms.TenChiNhanh, SoLuongMuon = pms.SoLuongMuon, NgayMuon = pms.NgayMuon }; DatabaseHelper.Add(res); pms.Id = res.Id; RedirectToAction(nameof(Index)); } return(View(pms)); }
public IActionResult Edit(MuonSachView t, string Id, string MaPhieu, string Ten, string Tens, string Tencn, string slm, string ngaym) { ViewBag.Id = Id; ViewBag.MP = MaPhieu; ViewBag.Ten = Ten; ViewBag.TenSach = Tens; ViewBag.TenCN = Tencn; ViewBag.SoLuong = slm; ViewBag.NgayMuon = ngaym; List <MuonSachView> li = new List <MuonSachView>(); var Store = DatabaseHelper.store; Store.Initialize(); using (var session = Store.OpenSession()) { t = session.Load <MuonSachView>(Id); } return(View(t)); }
public IActionResult AcceptEdit(string Id, string MaPhieu, string TenDG, string TenSach, string TenChiNhanh, int SoLuongMuon, string NgayMuon) { MuonSachView t = new MuonSachView(); ViewBag.Mp = TenDG; var sstore = DatabaseHelper.store; sstore.Initialize(); using (var session = sstore.OpenSession()) { t.Id = Id; t.MaPhieu = MaPhieu; t.TenDG = TenDG; t.TenSach = TenSach; t.TenChiNhanh = TenChiNhanh; t.SoLuongMuon = SoLuongMuon; t.NgayMuon = NgayMuon; session.Store(t); session.SaveChanges(); } return(View(t)); }