//loc cau tra loi theo chu de, template, ten cau hoi private IQueryable <BangFilterTraLoiVM> QueryListTraLoi(TraLoiSearchModel searchModel) { var listTraLoi = from ch in db.CauHois select ch; if (searchModel != null) { if (!String.IsNullOrEmpty(searchModel.IdChuDe)) { int id = Int32.Parse(searchModel.IdChuDe); listTraLoi = listTraLoi.Where(x => x.Template.IDChuDe == id); } if (!String.IsNullOrEmpty(searchModel.IdTemplate)) { int id = Int32.Parse(searchModel.IdTemplate); listTraLoi = listTraLoi.Where(x => x.IDTemplate == id); } if (!String.IsNullOrEmpty(searchModel.IDCauHoi)) { int id = Int32.Parse(searchModel.IDCauHoi); listTraLoi = listTraLoi.Where(x => x.IDCauHoi == id); } } var result = from ls in listTraLoi join ct in db.CauTraLoi_ChiTiet on ls.IDCauHoi equals ct.IDCauHoi into gj from g in gj.DefaultIfEmpty() group g by ls.TieuDe into gr select new BangFilterTraLoiVM() { TieuDe = gr.Key, SoLg = gr.Where(x => x.CauHoi.TieuDe == gr.Key).Select(x => x.IDCauTraLoiChiTiet).Count() }; return(result); }
// GET: Template public ActionResult Index(TraLoiSearchModel search) { var tem = QueryListTraLoi(search.IdChuDe); ViewBag.IdChuDe = new SelectList(db.ChuDes, "IDChuDe", "TenChuDe"); ThongKeTemplate thongKeT = new ThongKeTemplate(); thongKeT.bangTraLoi = tem.ToList(); return(View(thongKeT)); }
// GET: CauHoi public ActionResult Index(TraLoiSearchModel search) { var cauHoi = QueryListTraLoi(search); ViewBag.IdTemplate = new SelectList(db.Templates, "IDTemplate", "TenTemplate"); ViewBag.IdChuDe = new SelectList(db.ChuDes, "IDChuDe", "TenChuDe"); ThongKeCauHoi thongKeC = new ThongKeCauHoi(); thongKeC.bangTraLoi = cauHoi.ToList(); return(View(thongKeC)); }
// GET: ThongKe public ActionResult Index(TraLoiSearchModel searchModel) { ViewBag.IdChuDe = new SelectList(db.ChuDes, "IDChuDe", "TenChuDe"); ViewBag.IdTemplate = new SelectList(db.Templates, "IDTemplate", "TenTemplate"); var listCauHoi = db.CauHois.Select(x => new { x.TieuDe, x.IDCauHoi }).Distinct(); ViewBag.IdCauHoi = new SelectList(listCauHoi, "IDCauHoi", "TieuDe"); TempData["SoLgChuDe"] = db.ChuDes.Count(); TempData["SoLgTemplate"] = db.Templates.Count(); TempData["SoLgCauHoi"] = db.CauHois.Select(x => x.TieuDe).Distinct().Count(); ThongKeVM thongKe = new ThongKeVM(); thongKe.bangTraLoi = QueryListTraLoi(searchModel).ToList(); var resultTraLoi = QueryTraLoiRadioCheckbox(); var resultTextBox = QueryTraLoiTextBox(); var user = db.CauTraLois.Select(x => x); // loc de in ra man hinh if (searchModel != null) { if (searchModel.IdChuDe != null) { int id = Int32.Parse(searchModel.IdChuDe); resultTraLoi = resultTraLoi.Where(x => x.idChuDe == id); resultTextBox = resultTextBox.Where(x => x.idChuDe == id); user = user.Where(x => x.IDChuDe == id); } if (searchModel.IdTemplate != null) { int id = Int32.Parse(searchModel.IdTemplate); resultTraLoi = resultTraLoi.Where(x => x.idTemplate == id); resultTextBox = resultTextBox.Where(x => x.idTemplate == id); user = user.Where(x => x.IDTemplate == id); } if (searchModel.IDCauHoi != null) { int id = Int32.Parse(searchModel.IDCauHoi); resultTraLoi = resultTraLoi.Where(x => x.idCauHoi == id); resultTextBox = resultTextBox.Where(x => x.idCauHoi == id); } } thongKe.listThongKeTraLoi = resultTraLoi.ToList(); thongKe.listHoTen = user.Select(x => x.HoTen).ToList(); thongKe.listMssv = user.Select(x => x.MSNV).ToList(); thongKe.listEmail = user.Select(x => x.Email).ToList(); thongKe.listThongKeTextBox = resultTextBox.ToList(); return(View(thongKe)); }
// QueryListTraLoi public IQueryable <CauHoiVM> QueryListTraLoi(TraLoiSearchModel search) { var cauHois = from ch in db.CauHois select ch; if (search != null) { if (!String.IsNullOrEmpty(search.IdChuDe)) { int tableid = Int32.Parse(search.IdChuDe); cauHois = cauHois.Where(x => x.Template.IDChuDe == tableid); } if (!String.IsNullOrEmpty(search.IdTemplate)) { int tableid = Int32.Parse(search.IdTemplate); cauHois = cauHois.Where(x => x.IDTemplate == tableid); } } TempData["idChuDe"] = cauHois.Select(x => x.Template.IDChuDe).FirstOrDefault(); var TraLoiAll = from ch in cauHois join ct in db.CauTraLoi_ChiTiet on ch.IDCauHoi equals ct.IDCauHoi group ch by ch.IDCauHoi into gj from gr in gj.DefaultIfEmpty() select gr; var result = from ch in cauHois select new CauHoiVM() { IDCauHoi = ch.IDCauHoi, tenTemplate = ch.Template.TenTemplate, TieuDe = ch.TieuDe, IDLoaiCauHoi = ch.IDLoaiCauHoi, DangCauHoi = ch.LoaiCauHoi.DangCauHoi, CauHoiRequired = ch.CauHoiRequired, NgayTao = ch.NgayTao, NguoiTao = ch.NguoiTao, NgayUpdate = ch.NgayUpdate, NguoiUpdate = ch.NguoiUpdate, SoDiem = ch.SoDiem.Value, //CauHoiEnable = ch.CauHoiEnable.Value, SoLgTraLoi = TraLoiAll.Where(x => x.IDCauHoi == ch.IDCauHoi). Select(x => x.CauTraLoi_ChiTiet.FirstOrDefault().IDCauTraLoiChiTiet).Count(), SoLgNoiDung = ch.Sub_CauHoi.Where(x => x.IDCauHoi == ch.IDCauHoi).Count() }; return(result); }