public async Task <IndexCellViewModel> GetCellsAsync(CellFilterViewModel cellFilter, int page) { if (cellFilter == null) { cellFilter = new CellFilterViewModel(); cellFilter.SortItem = ""; cellFilter.SearchValue = ""; cellFilter.SearchFilter = ""; } cellFilter.SearchValue = cellFilter.SearchValue == null ? "Any" : cellFilter.SearchValue; cellFilter.SearchFilter = cellFilter.SearchFilter == null ? "" : cellFilter.SearchFilter; cellFilter.SortItem = cellFilter.SortItem == null ? "" : cellFilter.SortItem; IEnumerable <Cell> cells = OrderByCell(await FilterSearch(cellFilter), cellFilter.SortItem); var count = cells.Count(); var skipCells = cells.Skip((page - 1) * 6).Take(6).ToList(); if (skipCells.Count == 0 && page != 1) { skipCells = cells.Skip((page - 2) * 6).Take(6).ToList(); page -= 1; } var list = ListCells(skipCells); PageViewModel pageViewModel = new PageViewModel(count, page, 6); IndexCellViewModel viewModel = new IndexCellViewModel { PageViewModel = pageViewModel, Cells = list, CellFilterViewModel = cellFilter }; return(viewModel); }
public async Task <IActionResult> StorageCells([Bind("StorageId," + "MinWidth, MaxWidth, MinHeight, MaxHeight, MinLength, MaxLength, MinCapacity," + "MaxCapacity,SearchValue,SearchFilter,SortItem,FirstDate,SecondDate")] CellFilterViewModel cellFilterViewModel, int page = 1) { var errMsg = TempData["ErrorMessage"]; if (errMsg != null) { ModelState.AddModelError("", errMsg as string); } var storageCells = await _storageRepository.GetCellsAsync(cellFilterViewModel, page); return(View(storageCells)); }
public async Task <IActionResult> GetAllCells([Bind("MinWidth," + "MaxWidth, MinHeight, MaxHeight, MinLength, MaxLength, MinCapacity," + "MaxCapacity,SearchValue,SearchFilter,SortItem")] CellFilterViewModel cellFilterViewModel, int page = 1) { var errMsg = TempData["ErrorMessage"]; cellFilterViewModel.StorageId = -1;//кастыль что бы взять все ячейки if (errMsg != null) { ModelState.AddModelError("", errMsg as string); } var storageCells = await _storageRepository.GetCellsAsync(cellFilterViewModel, page); return(View(nameof(StorageCells), storageCells)); }
public async Task <IEnumerable <Cell> > FilterSearch(CellFilterViewModel cellFilter) { IQueryable <Cell> list; if (cellFilter.StorageId == -1) { list = dataContext.Cells .AsNoTracking() .Include(x => x.Standard) .Include(x => x.Reservations); } else { list = dataContext.Cells .AsNoTracking() .Include(x => x.Standard) .Include(x => x.Reservations) .Where(x => x.StorageId == cellFilter.StorageId); } //if(cellFilter.FirstDate != null && cellFilter.SecondDate != null) //{ // list = list.Where(x => // x.Reservations.Any(reserve => // (reserve.StartReservation < cellFilter.FirstDate && // reserve.EndReservation > cellFilter.FirstDate) || // (cellFilter.FirstDate < reserve.StartReservation && // cellFilter.SecondDate > reserve.StartReservation) && !reserve.Status)); //} if (cellFilter.MaxWidth == 0 && cellFilter.MinWidth != 0) { list = list.Where(x => x.Width >= cellFilter.MinWidth); } else if (cellFilter.MaxWidth != 0 && cellFilter.MinWidth != 0) { list = list.Where(x => x.Width >= cellFilter.MinWidth && x.Width <= cellFilter.MaxWidth); } if (cellFilter.MaxHeight == 0 && cellFilter.MinHeight != 0) { list = list.Where(x => x.Height >= cellFilter.MinHeight); } else if (cellFilter.MaxHeight != 0 && cellFilter.MinHeight != 0) { list = list.Where(x => x.Height >= cellFilter.MinHeight && x.Height <= cellFilter.MaxHeight); } if (cellFilter.MaxLength == 0 && cellFilter.MinLength != 0) { list = list.Where(x => x.Length >= cellFilter.MinLength); } else if (cellFilter.MaxLength != 0 && cellFilter.MinLength != 0) { list = list.Where(x => x.Length >= cellFilter.MinLength && x.Length <= cellFilter.MaxLength); } if (cellFilter.MaxCapacity == 0 && cellFilter.MinCapacity != 0) { list = list.Where(x => x.Capacity >= cellFilter.MinCapacity); } else if (cellFilter.MaxCapacity != 0 && cellFilter.MinCapacity != 0) { list = list.Where(x => x.Capacity >= cellFilter.MinCapacity && x.Capacity <= cellFilter.MaxCapacity); } switch (cellFilter.SearchValue) { case "Width": return(await list .Where(x => x.Width.ToString().Contains(cellFilter.SearchFilter)) .ToListAsync()); case "Height": return(await list .Where(x => x.Height.ToString().Contains(cellFilter.SearchFilter)) .ToListAsync()); case "Length": return(await list .Where(x => x.Length.ToString().Contains(cellFilter.SearchFilter)) .ToListAsync()); case "Capacity": return(await list .Where(x => x.Capacity.ToString().Contains(cellFilter.SearchFilter)) .ToListAsync()); case "Standart_Id": return(await list .Where(x => x.StandardId.ToString().Contains(cellFilter.SearchFilter)) .ToListAsync()); case "Standart_Price": return(await list .Where(x => x.Standard.Price.ToString().Contains(cellFilter.SearchFilter)) .ToListAsync()); case "Status": bool statusFilter = cellFilter.SearchFilter == "Active" || cellFilter.SearchFilter == "active" || cellFilter.SearchFilter == "True" || cellFilter.SearchFilter == "true" || cellFilter.SearchFilter == "1"; return(await list .Where(x => x.Status == statusFilter) .ToListAsync()); default: return(await list .Where(x => x.Standard.Price.ToString().Contains(cellFilter.SearchFilter) || x.StandardId.ToString().Contains(cellFilter.SearchFilter) || x.Capacity.ToString().Contains(cellFilter.SearchFilter) || x.Height.ToString().Contains(cellFilter.SearchFilter) || x.Length.ToString().Contains(cellFilter.SearchFilter) || x.Width.ToString().Contains(cellFilter.SearchFilter) || x.Status.ToString().Contains(cellFilter.SearchFilter) || x.CellId.ToString().Contains(cellFilter.SearchFilter) ) .ToListAsync()); } }