private IList GetListItems(StudentWorkViewModel model) { using (DataContext ctx = new DataContext()) { return(ctx.StudentWork .AsNoTracking() .Where(t => (t.TeacherId == Authentication.User.UserId || t.StudentId == Authentication.User.UserId || Authentication.IsAdmin)) .OrderByDescending(t => t.WorkDate) .ToList() .Where(t => (model == null || model.PredmetId == null || t.PredmetId == model.PredmetId) && (model == null || model.WorkTypeId == null || t.WorkTypeId == model.WorkTypeId) && (model == null || model.TeacherId == null || t.TeacherId == model.TeacherId) && (model == null || model.StudentGroupId == null || t.Student.StudentGroupId == model.StudentGroupId) && (model == null || string.IsNullOrEmpty(model.WorkStatus) || t.WorkStatus == model.WorkStatus)) .Select(t => new { Id = t.Id, t.WorkDate, t.WorkStatus, WorkType = t.WorkType.Name, Teacher = t.Teacher.UserName, Student = t.Student.UserName, Predmet = t.Predmet.Name, StudentGroup = t.Student?.StudentGroup?.Name }) .ToList()); } }
public ActionResult Index(StudentWorkViewModel model) { if (model == null || model.Id == null) { model = (Session["StudentWorkViewModel"] as StudentWorkViewModel); if (model == null) { model = new StudentWorkViewModel(); model.Id = 0; } } else { Session["StudentWorkViewModel"] = model; } ViewBag.Items = GetListItems(model); PrepareViewBag(); return(View("Index", model)); }