public ActionResult Index(int?coach, string name, SortState sortOrder = SortState.NameAsc) { ViewBag.Title = "Visitors info"; //IQueryable<GymVisitor> users = db.GymVisitors.Include(p => p.CoachId); IQueryable <GymVisitor> users = db.GymVisitors.Where(p => p.CoachId != null); ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc; users = sortOrder switch { SortState.NameDesc => users.OrderByDescending(s => s.LastName), SortState.CompanyAsc => users.OrderBy(s => s.LastName), SortState.CompanyDesc => users.OrderByDescending(s => s.LastName), _ => users.OrderBy(s => s.LastName), }; if (coach != null && coach != 0) { users = users.Where(p => p.CoachId == coach); } if (!String.IsNullOrEmpty(name)) { users = users.Where(p => p.LastName.Contains(name)); } List <GymCoach> coaches = db.GymCoaches.ToList(); // устанавливаем начальный элемент, который позволит выбрать всех coaches.Insert(0, new GymCoach { Id = 0, LastName = "All" }); InfoVIewModel viewModel = new InfoVIewModel { GymVisitors = users.ToList(), Coaches = new SelectList(coaches, "Id", "LastName"), SecondName = name, GymCoaches = coaches }; return(View(viewModel)); }
public IActionResult Index(string searchString, SortState sortOrder = SortState.TitleAsc) { var items = this.dataManager.Items.GetItems(); ViewData["ItemNameSort"] = sortOrder == SortState.TitleAsc ? SortState.DateDesc : SortState.TitleAsc; ViewData["ItemDateSort"] = sortOrder == SortState.DateDesc ? SortState.TitleAsc : SortState.DateDesc; items = sortOrder switch { SortState.TitleAsc => items.OrderBy(i => i.Title), SortState.DateDesc => items.OrderByDescending(i => i.TimeAdded), _ => items.OrderBy(i => i.Title), }; if (!string.IsNullOrEmpty(searchString)) { items = items.Where(i => (i.Title.Contains(searchString) || searchString.Contains(i.Title)) || (i.Theme.Contains(searchString) || searchString.Contains(i.Theme))); } return(View(new ItemsViewModel(items.AsNoTracking()))); }
public IActionResult Index(string searchString, SortState sortOrderItem = SortState.DateDesc, SortState sortOrderCollection = SortState.DateDesc) { var collections = this.manager.Collections.GetCollections(); var items = this.manager.Items.GetItems(); ViewData["CollectionNameSort"] = sortOrderCollection == SortState.TitleAsc ? SortState.DateDesc : SortState.TitleAsc; ViewData["CollectionDateSort"] = sortOrderCollection == SortState.DateDesc ? SortState.TitleAsc : SortState.DateDesc; ViewData["ItemNameSort"] = sortOrderItem == SortState.TitleAsc ? SortState.DateDesc : SortState.TitleAsc; ViewData["ItemDateSort"] = sortOrderItem == SortState.DateDesc ? SortState.TitleAsc : SortState.DateDesc; collections = sortOrderCollection switch { SortState.TitleAsc => collections.OrderBy(c => c.Title), SortState.DateDesc => collections.OrderByDescending(c => c.TimeAdded), _ => collections.OrderBy(c => c.Title), }; items = sortOrderItem switch { SortState.TitleAsc => items.OrderBy(i => i.Title), SortState.DateDesc => items.OrderByDescending(i => i.TimeAdded), _ => items.OrderBy(i => i.Title), }; if (!string.IsNullOrEmpty(searchString)) { items = items.Where(i => (i.Title.Contains(searchString) || searchString.Contains(i.Title)) || i.Theme.Contains(searchString) || searchString.Contains(i.Theme)); collections = collections.Where(c => (c.Title.Contains(searchString) || searchString.Contains(c.Title)) || (c.Description.Contains(searchString) || searchString.Contains(c.Description)) || (c.Theme.Contains(searchString) || searchString.Contains(c.Theme))); } return(View(new HomeViewModel(collections.AsNoTracking().ToList(), items.AsNoTracking().ToList(), this.manager.Tags.GetTags().AsNoTracking().ToList()))); }
public IActionResult Index(string searchString, SortState sortOrder = SortState.TitleAsc) { var collections = this.dataManager.Collections.GetCollections(); ViewData["CollectionNameSort"] = sortOrder == SortState.TitleAsc ? SortState.DateDesc : SortState.TitleAsc; ViewData["CollectionDateSort"] = sortOrder == SortState.DateDesc ? SortState.TitleAsc : SortState.DateDesc; collections = sortOrder switch { SortState.TitleAsc => collections.OrderBy(c => c.Title), SortState.DateDesc => collections.OrderByDescending(c => c.TimeAdded), _ => collections.OrderBy(c => c.Title), }; if (!string.IsNullOrEmpty(searchString)) { collections = collections.Where(c => (c.Title.Contains(searchString) || searchString.Contains(c.Title)) || (c.Description.Contains(searchString) || searchString.Contains(c.Description)) || (c.Theme.Contains(searchString) || searchString.Contains(c.Theme))); } return(View(new CollectionsViewModel(collections.AsNoTracking()))); }
/// <summary> /// Выводит всех сотрудников с фильтром /// </summary> /// <param name="positionId"></param> /// <param name="departamentId"></param> /// <returns></returns> public async Task <IActionResult> Index(int?positionId, int?departamentId, string?find_str, SortState sortOrder = SortState.NameAsc) { //Создаю подключение при первом запуске, если БД нет, то создаю ее и все //сопутствующие представления и хранимые процедуры await Createdatabase(); ViewData["NameSort"] = sortOrder == SortState.NameAsc ? SortState.NameDesc : SortState.NameAsc; List <PositionViewModel> positionsModel = _db.GetAllPositionsStoreProc() .Result .Select(p => new PositionViewModel { Id = p.Id, Name = p.Name }) .ToList(); positionsModel.Insert(0, new PositionViewModel { Id = 0, Name = "Все" }); List <DepViewModel> depModel = _db.GetAllDepStoreProc() .Result .Select(d => new DepViewModel { Id = d.Id, Name = d.Name }) .ToList(); depModel.Insert(0, new DepViewModel { Id = 0, Name = "Все" }); IQueryable <Employee> emplModel = null; if (String.IsNullOrEmpty(find_str)) { emplModel = _db.GetAllEmployersStoreProc().Result; } else { emplModel = _db.FindEmploees(find_str).Result; } emplModel.OrderByDescending(d => d.LastName); emplModel = sortOrder switch { SortState.NameDesc => emplModel.OrderByDescending(s => s.LastName), _ => emplModel.OrderBy(s => s.LastName), }; IndexViewModel ivm = new IndexViewModel { Positions = positionsModel, Deps = depModel, Employers = emplModel }; if (positionId != null && positionId > 0) { ivm.Employers = (IQueryable <Employee>)emplModel.Where(e => e.PositionId == positionId); } if (departamentId != null && departamentId > 0) { ivm.Employers = (IQueryable <Employee>)emplModel.Where(e => e.DepId == departamentId); } return(View(ivm)); }