public virtual ActionResult List(string term = "", int page = 1, int count = 10, Order order = Order.Descending, ElectionSearchBy objSearchBy = ElectionSearchBy.Score, ElectionOrderBy objOrderBy = ElectionOrderBy.Id) { //#region Retrive Data int total; var articles = _ElectionService.GetDataTable(out total, term, page, order, objSearchBy, objOrderBy, count); var model = new ElectionListVM { Order = order, PageCount = count, PageNumber = page, ElectionList = articles, Term = term, TotalElections = total }; ViewBag.CountList = DropDown.GetCountList(count); ViewBag.OrderList = DropDown.GetOrderList(order); return(PartialView("_ListPartial", model)); }
public virtual ActionResult List(string term = "", int page = 1, int count = 10, Order order = Order.Descending, ScoreStateType objSearchBy = ScoreStateType.Score, ElectionOrderBy objOrderBy = ElectionOrderBy.Id) { string userName = HttpContext.User.Identity.Name; Professor pro = _ProfessorService.GetByUserId(_UserService.GetUserByUserName(userName).Id); //#region Retrive Data int total; var articles = _ElectionService.GetDataTableForScore(out total, term, page, order, objSearchBy, objOrderBy, pro.Id, count); var model = new ScoreListVM { Order = order, PageCount = count, PageNumber = page, ScoreList = articles, Term = term, TotalElections = total }; ViewBag.CountList = DropDown.GetCountList(count); ViewBag.OrderList = DropDown.GetOrderList(order); return(PartialView("_ListPartial", model)); }
public IEnumerable <ScoreViewModel> GetDataTableForStudentScore(out int total, string term, int?Term_id, int page, Order order, ScoreStateType slectionSearchBy, ElectionOrderBy slectionOrderBy, long Student_id, int count = 10) { var selectedobj = _Election .Include(x => x.PeresentedCource) .Include(x => x.Student) .Where(x => x.Student.Id == Student_id) .AsNoTracking().AsQueryable(); if (Term_id.HasValue) { selectedobj = selectedobj.Where(x => x.PeresentedCource.Term.Id == Term_id.Value).AsQueryable(); } if (!string.IsNullOrEmpty(term)) { switch (slectionSearchBy) { case ScoreStateType.NotScore: selectedobj = selectedobj.Where(a => !a.Score.HasValue).AsQueryable(); break; case ScoreStateType.Score: selectedobj = selectedobj.Where(a => a.Score.HasValue).AsQueryable(); break; } } if (order == Order.Asscending) { switch (slectionOrderBy) { case ElectionOrderBy.Id: selectedobj = selectedobj.OrderBy(x => x.Id).AsQueryable(); break; case ElectionOrderBy.Score: selectedobj = selectedobj.OrderBy(x => x.Score).AsQueryable(); break; } } else { switch (slectionOrderBy) { case ElectionOrderBy.Id: selectedobj = selectedobj.OrderByDescending(x => x.Id).AsQueryable(); break; case ElectionOrderBy.Score: selectedobj = selectedobj.OrderByDescending(x => x.Score).AsQueryable(); break; } } var totalQuery = selectedobj.FutureCount(); var query = selectedobj.Skip((page - 1) * count).Take(count) .Select(a => new ScoreViewModel { Id = a.Id, Score = (a.Score.HasValue)?a.Score.Value:0, PeresentedCource = a.PeresentedCource, Student = a.Student }).Future(); foreach (var item in query) { item.Average = query.Average(x => x.Score.Value * x.PeresentedCource.Course.Unit); } total = totalQuery.Value; var categories = query.ToList(); return(categories); }
public IEnumerable <ElectionViewModel> GetDataTable(out int total, string term, int page, Order order, ElectionSearchBy slectionSearchBy, ElectionOrderBy slectionOrderBy, int count = 10) { var selectedobj = _Election .Include(x => x.PeresentedCource) .Include(x => x.Student) .AsNoTracking().AsQueryable(); if (!string.IsNullOrEmpty(term)) { switch (slectionSearchBy) { case ElectionSearchBy.Peresented_Cource_Name: selectedobj = selectedobj.Where(a => a.PeresentedCource.Course.Name.Contains(term)).AsQueryable(); break; case ElectionSearchBy.Score: selectedobj = selectedobj.Where(a => a.Score == Convert.ToDecimal(term)).AsQueryable(); break; case ElectionSearchBy.StudentName: selectedobj = selectedobj.Where(a => a.Student.FirstName.Contains(term) || a.Student.LastName.Contains(term)).AsQueryable(); break; } } if (order == Order.Asscending) { switch (slectionOrderBy) { case ElectionOrderBy.Id: selectedobj = selectedobj.OrderBy(x => x.Id).AsQueryable(); break; case ElectionOrderBy.Score: selectedobj = selectedobj.OrderBy(x => x.Score).AsQueryable(); break; } } else { switch (slectionOrderBy) { case ElectionOrderBy.Id: selectedobj = selectedobj.OrderByDescending(x => x.Id).AsQueryable(); break; case ElectionOrderBy.Score: selectedobj = selectedobj.OrderByDescending(x => x.Score).AsQueryable(); break; } } var totalQuery = selectedobj.FutureCount(); var query = selectedobj.Skip((page - 1) * count).Take(count) .Select(a => new ElectionViewModel { Id = a.Id, Score = a.Score, PeresentedCource = a.PeresentedCource, Student = a.Student }).Future(); total = totalQuery.Value; var categories = query.ToList(); return(categories); }