public List <CauHoiViewModel> GetCauHoiList(string cauhoi, int startIndex, int count, string sorting) { // Instance of DatabaseContext try { using (var db = new DatabaseContext()) { var data = from cauhoii in db.CauHois where cauhoii.Status == true select new CauHoiViewModel() { ID = cauhoii.ID, IDDeThi = cauhoii.IDDeThi, DeBai = cauhoii.DeBai, PhuongAnA = cauhoii.PhuongAnA, PhuongAnB = cauhoii.PhuongAnB, PhuongAnC = cauhoii.PhuongAnC, PhuongAnD = cauhoii.PhuongAnD, DapAn = cauhoii.DapAn, Status = cauhoii.Status }; IEnumerable <CauHoiViewModel> query = data.ToList(); foreach (var item in query) { var cc = _iDeThi.GetDeThiById(item.IDDeThi); if (cc != null) { item.TenDeThi = cc.TenDeThi; } } //Search if (cauhoi != null) { query = query.Where(p => p.DapAn.Contains(cauhoi)); } //Sorting Ascending and Descending if (string.IsNullOrEmpty(sorting) || sorting.Equals("AssignedRoleId ASC")) { query = query.OrderBy(p => p.ID); } else { query = query.OrderBy(p => p.DapAn); //Default! } return(count > 0 ? query.Skip(startIndex).Take(count).ToList() //Paging : query.ToList()); //No paging } } catch (Exception ex) { throw; } }
public ActionResult AcLoadQuiz() { var i = ((long?)Session["UserID"] ?? 0); var c = _iToChucThi.GetListIDUser((int)i); var l = _iDethi.GetDeThiById(c.LastOrDefault().IDDeThi); var ch = _iCauHoi.GetGetListCauHoiDeThiById(l.ID); string json = JsonConvert.SerializeObject(ch); return(Json(json)); }
public List <ToChucThiViewModel> GetToChucThiList(string monthi, int startIndex, int count, string sorting) { // Instance of DatabaseContext try { using (var db = new DatabaseContext()) { var data = from tochuc in db.ToChucThis where tochuc.Status == true select new ToChucThiViewModel() { ID = tochuc.ID, IDUser = tochuc.IDUser, IDDeThi = tochuc.IDDeThi, Status = tochuc.Status }; IEnumerable <ToChucThiViewModel> query = data.ToList(); foreach (var item in query) { var c = _userMaster.GetUserById(item.IDUser); var d = _deThi.GetDeThiById(item.IDDeThi); item.TenUser = c != null ? c.UserName : ""; item.TenDeThi = d != null ? d.TenDeThi : ""; } //Search //Sorting Ascending and Descending if (string.IsNullOrEmpty(sorting) || sorting.Equals("AssignedRoleId ASC")) { query = query.OrderBy(p => p.ID); } return(count > 0 ? query.Skip(startIndex).Take(count).ToList() //Paging : query.ToList()); //No paging } } catch (Exception ex) { throw; } }