/// <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)); }