// GET: NhaKhoaHocs public async Task <ActionResult> Index(int?Page_No, [Bind(Include = "MaDonVi,MaNgach,MaHocHam,MaHocVi,MaCNDaoTao,SearchValue")] NhaKhoaHocSearchViewModel nhaKhoaHoc) { ViewBag.MaCNDaoTao = new SelectList(db.ChuyenNganhs.ToList(), "MaChuyenNganh", "TenChuyenNganh"); ViewBag.MaDonViQL = new SelectList(db.DonViQLs.ToList(), "MaDonVi", "TenDonVI"); ViewBag.MaHocHam = new SelectList(db.HocHams.ToList(), "MaHocHam", "TenHocHam"); ViewBag.MaHocVi = new SelectList(db.HocVis.ToList(), "MaHocVi", "TenHocVi"); ViewBag.MaNgachVienChuc = new SelectList(db.NgachVienChucs.ToList(), "MaNgach", "TenNgach"); var pre = PredicateBuilder.True <NhaKhoaHoc>(); if (!String.IsNullOrEmpty(nhaKhoaHoc.MaCNDaoTao) && nhaKhoaHoc.MaCNDaoTao != "0") { pre = pre.And(p => p.MaCNDaoTao.ToString() == nhaKhoaHoc.MaCNDaoTao); } if (!String.IsNullOrEmpty(nhaKhoaHoc.MaDonVi) && nhaKhoaHoc.MaDonVi != "0") { pre = pre.And(p => p.MaDonViQL.ToString() == nhaKhoaHoc.MaDonVi); } if (!String.IsNullOrEmpty(nhaKhoaHoc.MaHocHam) && nhaKhoaHoc.MaHocHam != "0") { pre = pre.And(p => p.MaHocHam.ToString() == nhaKhoaHoc.MaHocHam); } if (!String.IsNullOrEmpty(nhaKhoaHoc.MaHocVi) && nhaKhoaHoc.MaHocVi != "0") { pre = pre.And(p => p.MaHocVi.ToString() == nhaKhoaHoc.MaHocVi); } if (!String.IsNullOrEmpty(nhaKhoaHoc.MaNgach) && nhaKhoaHoc.MaNgach != "0") { pre = pre.And(p => p.MaNgachVienChuc.ToString() == nhaKhoaHoc.MaNgach); } if (!String.IsNullOrEmpty(nhaKhoaHoc.SearchValue)) { pre = pre.And(p => (p.HoNKH + " " + p.TenNKH).ToLower().Contains(nhaKhoaHoc.SearchValue.ToLower())); } ViewBag.SearchValue = nhaKhoaHoc.SearchValue; int No_Of_Page = (Page_No ?? 1); var nhaKhoaHocs = db.NhaKhoaHocs.Include(n => n.ChuyenNganh).Include(n => n.DonViQL).Include(n => n.HocHam).Include(n => n.HocVi).Include(n => n.NgachVienChuc).AsExpandable().Where(pre).OrderBy(p => p.MaNKH).Skip((No_Of_Page - 1) * 6).Take(6).ToList(); var lstNKH = new List <NhaKhoaHocViewModel>(); for (int i = 0; i < nhaKhoaHocs.Count; i++) { NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHocs[i]); lstNKH.Add(nkh); } decimal totalItem = (decimal)db.NhaKhoaHocs.Where(pre).OrderBy(p => p.MaNKH).Count(); int totalPage = (int)Math.Ceiling(totalItem / 6); ViewBag.TotalItem = totalItem; IPagedList <NhaKhoaHocViewModel> pageOrders = new StaticPagedList <NhaKhoaHocViewModel>(lstNKH, No_Of_Page, 1, totalPage); return(View(pageOrders)); }
// GET: NhaKhoaHocs/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhaKhoaHoc nhaKhoaHoc = await db.NhaKhoaHocs.FindAsync(id); if (nhaKhoaHoc == null) { return(HttpNotFound()); } ViewBag.MaCNDT = new SelectList(db.ChuyenNganhs, "MaChuyenNganh", "TenChuyenNganh", nhaKhoaHoc.MaCNDaoTao); ViewBag.MaDVQL = new SelectList(db.DonViQLs, "MaDonVi", "TenDonVI", nhaKhoaHoc.MaDonViQL); ViewBag.MaHH = new SelectList(db.HocHams, "MaHocHam", "TenHocHam", nhaKhoaHoc.MaHocHam); ViewBag.MaHV = new SelectList(db.HocVis, "MaHocVi", "TenHocVi", nhaKhoaHoc.MaHocVi); ViewBag.MaNgachVC = new SelectList(db.NgachVienChucs, "MaNgach", "TenNgach", nhaKhoaHoc.MaNgachVienChuc); var lstAllTrinhDoNN = db.TrinhDoNgoaiNgus.Select(p => new { p.MaTrinhDoNN, TenTD = p.TenTrinhDo }).ToList(); var lstTrinhDoNN = db.TrinhDoNgoaiNgus.Where(p => p.NgoaiNguNKHs.Select(nn => nn.MaNKH).Contains(nhaKhoaHoc.MaNKH)).Select(t => t.MaTrinhDoNN).ToList(); //var lstTrinhDoNN = db.TrinhDoNgoaiNgus.Where(p => p.NhaKhoaHocs.Select(t => t.MaNKH).Contains(nhaKhoaHoc.MaNKH)).Select(p => p.MaTrinhDoNN).ToList(); ViewBag.DSTrinhDoNgoaiNgu = new MultiSelectList(lstAllTrinhDoNN, "MaTrinhDoNN", "TenTD", lstTrinhDoNN); var lstAllLinhVucNC = db.LinhVucs.Select(p => new { p.MaLinhVuc, TenLV = p.TenLinhVuc }); var lstLinhVucNC = db.LinhVucs.Where(p => p.NhaKhoaHocs.Select(t => t.MaNKH).Contains(nhaKhoaHoc.MaNKH)).Select(t => t.MaLinhVuc) .ToList(); ViewBag.DSLinhVucNghienCuu = new MultiSelectList(lstAllLinhVucNC, "MaLinhVuc", "TenLV", lstLinhVucNC); var lstAllChuyenMonGD = db.ChuyenMons.Select(p => new { p.MaChuyenMon, TenCM = p.TenChuyenMon }); var lstChuyenMonGD = db.ChuyenMonNKHs.Where(p => p.MaNKH == nhaKhoaHoc.MaNKH).Select(p => p.MaChuyenMon) .ToList(); ViewBag.DSChuyenMonGiangDay = new MultiSelectList(lstAllChuyenMonGD, "MaChuyenMon", "TenCM", lstChuyenMonGD); NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHoc); return(View(nkh)); }
// GET: AdminNhaKhoaHoc public async Task <ActionResult> Index() { var nhaKhoaHocs = db.NhaKhoaHocs.Include(n => n.ChuyenNganh).Include(n => n.DonViQL).Include(n => n.HocHam).Include(n => n.HocVi).Include(n => n.NgachVienChuc).ToList(); var lstNKH = new List <NhaKhoaHocViewModel>(); for (int i = 0; i < nhaKhoaHocs.Count; i++) { NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHocs[i]); lstNKH.Add(nkh); } return(View(lstNKH)); }
public async Task <ActionResult> GetReport(int?id) { UserLoginViewModel user = Session["user"] as UserLoginViewModel; if (id == null || user == null || user.MaNKH != id) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhaKhoaHoc nhaKhoaHoc = await db.NhaKhoaHocs.FindAsync(id); NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHoc); if (nhaKhoaHoc == null) { return(HttpNotFound()); } return(View(nkh)); }
// GET: NhaKhoaHocs/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhaKhoaHoc nhaKhoaHoc = await db.NhaKhoaHocs.FindAsync(id); if (nhaKhoaHoc == null) { return(HttpNotFound()); } ViewBag.MaCNDaoTao = new SelectList(db.ChuyenNganhs, "MaChuyenNganh", "TenChuyenNganh"); ViewBag.MaDonViQL = new SelectList(db.DonViQLs, "MaDonVi", "TenDonVI"); ViewBag.MaHocHam = new SelectList(db.HocHams, "MaHocHam", "TenHocHam"); ViewBag.MaHocVi = new SelectList(db.HocVis, "MaHocVi", "TenHocVi"); ViewBag.MaNgachVienChuc = new SelectList(db.NgachVienChucs, "MaNgach", "TenNgach"); NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHoc); return(View(nkh)); }
public async Task <ActionResult> Search([Bind(Include = "MaDanhMuc,MaDonViQLThucHien,SearchValue")] HomeSearchViewModel home) { ViewBag.SearchValue = home.SearchValue; int Size_Of_Page = 6; int No_Of_Page = 1; switch (home.MaDanhMuc) { case "1": ViewBag.MaCapDeTai = new SelectList(db.CapDeTais, "MaCapDeTai", "TenCapDeTai"); ViewBag.MaDonViQLThucHien = new SelectList(db.DonViQLs, "MaDonVi", "TenDonVI"); ViewBag.MaLinhVuc = new SelectList(QLKHrepo.GetListMenuLinhVuc(), "Id", "TenLinhVuc"); var detais = db.DeTais.Include(d => d.CapDeTai).Include(d => d.LoaiHinhDeTai).Include(d => d.DonViChuTri).Include(d => d.DonViQL).Include(d => d.LinhVuc).Include(d => d.XepLoai).Include(d => d.TinhTrangDeTai).Include(d => d.PhanLoaiSP).ToList(); if (!String.IsNullOrEmpty(home.MaDonViQLThucHien) && home.MaDonViQLThucHien != "0") { detais = detais.Where(p => p.MaDonViQLThucHien.ToString() == home.MaDonViQLThucHien).ToList(); } if (!String.IsNullOrEmpty(home.SearchValue)) { detais = detais.Where(p => p.TenDeTai.ToLower().Contains(home.SearchValue.ToLower())).ToList(); } int totalPage1 = (int)Math.Ceiling((decimal)detais.Count() / 6); ViewBag.TotalItem = detais.Count(); IPagedList <DeTai> pageOrders1 = new StaticPagedList <DeTai>(detais, No_Of_Page, 1, totalPage1); return(View("~/Views/DeTais/Index.cshtml", pageOrders1)); case "2": ViewBag.MaLinhVuc = new SelectList(QLKHrepo.GetListMenuLinhVuc(), "Id", "TenLinhVuc"); ViewBag.MaCapTapChi = new SelectList(db.CapTapChis, "MaCapTapChi", "TenCapTapChi"); ViewBag.MaPhanLoaiTapChi = new SelectList(db.PhanLoaiTapChis, "MaLoaiTapChi", "TenLoaiTapChi"); ViewBag.MaLoaiTapChi = new List <SelectListItem> { new SelectListItem { Text = "Trong Nước", Value = "1" }, new SelectListItem { Text = "Ngoài Nước", Value = "0" }, }; var baibaos = db.BaiBaos.Include(b => b.CapTapChi).Include(b => b.PhanLoaiTapChi).ToList(); if (!String.IsNullOrEmpty(home.SearchValue)) { baibaos = baibaos.Where(p => p.TenBaiBao.ToLower().Contains(home.SearchValue.ToLower())).ToList(); } int totalPage2 = (int)Math.Ceiling((decimal)baibaos.Count() / 6); ViewBag.TotalItem = baibaos.Count(); IPagedList <BaiBao> pageOrders2 = new StaticPagedList <BaiBao>(baibaos, No_Of_Page, 1, totalPage2); return(View("~/Views/BaiBaos/Index.cshtml", pageOrders2)); case "3": ViewBag.MaLinhVuc = new SelectList(QLKHrepo.GetListMenuLinhVuc(), "Id", "TenLinhVuc"); ViewBag.MaNXB = new SelectList(db.NhaXuatBans, "MaNXB", "TenNXB"); ViewBag.MaLoai = new SelectList(db.PhanLoaiSaches, "MaLoai", "TenLoai"); var sachGiaoTrinhs = db.SachGiaoTrinhs.Include(s => s.LinhVuc).Include(s => s.NhaXuatBan).Include(s => s.PhanLoaiSach).ToList(); if (!String.IsNullOrEmpty(home.SearchValue)) { sachGiaoTrinhs = sachGiaoTrinhs.Where(p => p.TenSach.ToLower().Contains(home.SearchValue.ToLower())).ToList(); } int totalPage3 = (int)Math.Ceiling((decimal)sachGiaoTrinhs.Count() / 6); ViewBag.TotalItem = sachGiaoTrinhs.Count(); IPagedList <SachGiaoTrinh> pageOrders3 = new StaticPagedList <SachGiaoTrinh>(sachGiaoTrinhs, No_Of_Page, 1, totalPage3); return(View("~/Views/SachGiaoTrinhs/Index.cshtml", pageOrders3)); default: ViewBag.MaCNDaoTao = new SelectList(db.ChuyenNganhs.ToList(), "MaChuyenNganh", "TenChuyenNganh"); ViewBag.MaHocHam = new SelectList(db.HocHams.ToList(), "MaHocHam", "TenHocHam"); ViewBag.MaHocVi = new SelectList(db.HocVis.ToList(), "MaHocVi", "TenHocVi"); ViewBag.MaDonViQL = new SelectList(db.DonViQLs.ToList(), "MaDonVi", "TenDonVI"); ViewBag.MaNgachVienChuc = new SelectList(db.NgachVienChucs.ToList(), "MaNgach", "TenNgach"); var nhaKhoaHocs = db.NhaKhoaHocs.Include(n => n.ChuyenNganh).Include(n => n.DonViQL).Include(n => n.HocHam).Include(n => n.HocVi).Include(n => n.NgachVienChuc).ToList(); if (!String.IsNullOrEmpty(home.MaDonViQLThucHien) && home.MaDonViQLThucHien != "0") { nhaKhoaHocs = nhaKhoaHocs.Where(p => p.MaDonViQL.ToString() == home.MaDonViQLThucHien).ToList(); } if (!String.IsNullOrEmpty(home.SearchValue)) { nhaKhoaHocs = nhaKhoaHocs.Where(p => (p.HoNKH + " " + p.TenNKH).ToLower().Contains(home.SearchValue.ToLower())).ToList(); } var lstNKH = new List <NhaKhoaHocViewModel>(); for (int i = 0; i < nhaKhoaHocs.Count; i++) { NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHocs[i]); lstNKH.Add(nkh); } int totalPage = (int)Math.Ceiling((decimal)lstNKH.Count() / 6); ViewBag.TotalItem = lstNKH.Count(); IPagedList <NhaKhoaHocViewModel> pageOrders = new StaticPagedList <NhaKhoaHocViewModel>(lstNKH, No_Of_Page, 1, totalPage); return(View("~/Views/NhaKhoaHocs/Index.cshtml", pageOrders)); } }
public async Task <ActionResult> Edit(HttpPostedFileBase fileUpload, List <int> DSLinhVucNC, List <int> DSChuyenMonGD, [Bind(Include = "MaNKH,MaNKHHoSo,HoNKH,TenNKH,GioiTinhNKH,NgaySinh,DiaChiLienHe,DienThoai,EmailLienHe,MaHocHam,MaHocVi,MaCNDaoTao,MaDonViQL,AnhDaiDien,MaNgachVienChuc")] NhaKhoaHoc nhaKhoaHoc, [Bind(Include = "MaNKH,STKNH,MaNH,ChiNhanhNH,GhiChu")] NganHangNKH nganHangNKH) { if (ModelState.IsValid) { // upload image var nhakh = db.NhaKhoaHocs.Where(p => p.MaNKH == nhaKhoaHoc.MaNKH).Include(p => p.LinhVucs).FirstOrDefault(); if (repo.HasFile(fileUpload)) { string mimeType = fileUpload.ContentType; Stream fileStream = fileUpload.InputStream; string fileName = Path.GetFileName(fileUpload.FileName); int fileLength = fileUpload.ContentLength; byte[] fileData = new byte[fileLength]; fileStream.Read(fileData, 0, fileLength); nhaKhoaHoc.AnhCaNhan = fileData; } db.NhaKhoaHocs.AddOrUpdate(nhaKhoaHoc); if (DSLinhVucNC != null) { var deletedlinhvuc = nhakh.LinhVucs.Where(p => !DSLinhVucNC.Contains(p.MaLinhVuc)).ToList(); var addedlinhvuc = DSLinhVucNC.Except(nhakh.LinhVucs.Select(p => p.MaLinhVuc)).ToList(); var addlinhvuc = db.LinhVucs.Where(p => addedlinhvuc.Contains(p.MaLinhVuc)).ToList(); foreach (var x in deletedlinhvuc) { nhakh.LinhVucs.Remove(x); } foreach (var x in addlinhvuc) { nhakh.LinhVucs.Add(x); } } else { foreach (var x in nhakh.LinhVucs) { nhakh.LinhVucs.Remove(x); } } /* * if (DSTrinhDoNN != null) { * var deletednn = nhakh.NgoaiNguNKHs.Where(p => !DSTrinhDoNN.Contains(p.MaTrinhDoNN)).ToList(); * var addednn = DSTrinhDoNN.Except(nhakh.NgoaiNguNKHs.Select(p => p.MaTrinhDoNN)).ToList(); * var addnn = db.TrinhDoNgoaiNgus.Where(p => addednn.Contains(p.MaTrinhDoNN)).ToList(); * foreach (var x in deletednn) * { * nhakh.NgoaiNguNKHs.Remove(x); * } * foreach (var x in addnn) * { * var newnn = new NgoaiNguNKH * { * MaNKH = nhakh.MaNKH, * MaTrinhDoNN = x.MaTrinhDoNN, * * }; * nhakh.NgoaiNguNKHs.Add(newnn); * } * } * else * { * foreach(var x in nhakh.NgoaiNguNKHs) * { * nhakh.NgoaiNguNKHs.Remove(x); * } * } */ if (DSChuyenMonGD != null) { db.ChuyenMonNKHs.Where(p => p.MaNKH == nhaKhoaHoc.MaNKH).ForEach(x => db.ChuyenMonNKHs.Remove(x)); foreach (var item in DSChuyenMonGD) { ChuyenMonNKH chuyenmonNKH = new ChuyenMonNKH { MaNKH = nhaKhoaHoc.MaNKH, MaChuyenMon = item, NgayCapNhat = DateTime.Now }; db.ChuyenMonNKHs.Add(chuyenmonNKH); db.SaveChanges(); } } if (nganHangNKH != null) { db.NganHangNKHs.AddOrUpdate(nganHangNKH); } await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.MaCNDaoTao = new SelectList(db.ChuyenNganhs, "MaChuyenNganh", "TenChuyenNganh", nhaKhoaHoc.MaCNDaoTao); ViewBag.MaDonViQL = new SelectList(db.DonViQLs, "MaDonVi", "TenDonVI", nhaKhoaHoc.MaDonViQL); ViewBag.MaHocHam = new SelectList(db.HocHams, "MaHocHam", "TenHocHam", nhaKhoaHoc.MaHocHam); ViewBag.MaHocVi = new SelectList(db.HocVis, "MaHocVi", "TenHocVi", nhaKhoaHoc.MaHocVi); ViewBag.MaNgachVienChuc = new SelectList(db.NgachVienChucs, "MaNgach", "TenNgach", nhaKhoaHoc.MaNgachVienChuc); NhaKhoaHocViewModel nkh = NhaKhoaHocViewModel.Mapping(nhaKhoaHoc); return(View(nkh)); }