public ActionResult LotList(int?page, LotSearchViewModel search) { int actualPage = page ?? 1; ViewBag.IsAdminOrModerator = false; IEnumerable <LotEntity> lots; if ((UserViewModel != null)) { ViewBag.IsAdminOrModerator = _customAuthentication.CheckUserInRoles(UserViewModel.ToUserEntity(), "Admin,Moderator"); } if (string.IsNullOrEmpty(search?.SearchString)) { lots = _lotService.GetAllLots(); } else { if (search.SearchInName) { lots = _lotService.GetLotsContainingStringInName(search.SearchString); } else { lots = _lotService.GetLotsContainingStringInDescription(search.SearchString); } } var pager = PagerViewModelCreator <LotViewModel> .GetPagerViewModel(lots.Select(x => x.ToLotViewModel()), actualPage, ItemsPerPage); ViewBag.SearchString = search?.SearchString; ViewBag.SearchInName = search?.SearchInName ?? true; return(PartialView(pager)); }
public IActionResult SearchLots() { ViewData["LotTypes"] = new SelectList(iLotTypeRepo.ListAllLotTypes(), "LotTypeID", "LotTypeName"); LotSearchViewModel searchViewModel = new LotSearchViewModel(); return(View(searchViewModel)); }
public async Task <IActionResult> List(int?saleId, string countryCode) { var lots = await this.auctionService.ListLotsAsync(saleId, countryCode); var viewModel = new LotSearchViewModel { Lots = lots }; return(View(viewModel)); }
public void ShouldSearchAllWeekdayLots() { //AAA test template //1) Arrange List <Lot> mockLotList = CreateMockLotData(); List <LotType> mockLotTypeList = CreateMockLotTypeData(); //logic not on implementation of interface but in controller mockLotRepo.Setup(m => m.ListAllLots()).Returns(mockLotList); mockLotTypeRepo.Setup(lt => lt.ListAllLotTypes()).Returns(mockLotTypeList); //Mock data injected into SearchLots controller method //How many lot objects/rows will be injected into that method? 4 LotSearchViewModel searchViewModel = new LotSearchViewModel(); searchViewModel.IsLotCurrentlyAvailable = true; searchViewModel.TypeOfDay = "Weekday"; int expectedNumberOfLots = 3; //2) Act //Casting(to match left and right sides of assignment) //testing logic of controller methods //Test post methods //SearchLots string sortOrder = null; string searchButton = null; bool isLotCurrentlyAvailable = false; string typeOfDay = null; int? lotTypeID = null; int InputPageSize = 3; int pageNumber = 1; ViewResult result = controller.SearchLotsResult(searchButton, sortOrder, isLotCurrentlyAvailable, typeOfDay, lotTypeID, pageNumber, searchViewModel, InputPageSize) as ViewResult; LotSearchViewModel resultModel = result.Model as LotSearchViewModel; List <Lot> lotList = resultModel.LotSearchResult.Data; int actualNumberOfLots = lotList.Count; //3) Assert //What is expected compared with the actual Assert.Equal(expectedNumberOfLots, actualNumberOfLots); }
//For user inputs, we will use a ViewModel //For Search, inputs from user, output (List) //[HttpPost] public IActionResult SearchLotsResult(string searchButton, string sortOrder, bool IsLotCurrentlyAvailable, string TypeOfDay, int?LotTypeID, int pageNumber, LotSearchViewModel searchViewModel, int InputPageSize = 2) { ViewData["LotNameSortParam"] = String.IsNullOrEmpty(sortOrder) ? "lotname_desc" : ""; ViewData["CurrentSortOrder"] = sortOrder; ViewData["LotTypes"] = new SelectList(iLotTypeRepo.ListAllLotTypes(), "LotTypeID", "LotTypeName"); if (searchButton == "Active") { IsLotCurrentlyAvailable = searchViewModel.IsLotCurrentlyAvailable; ViewData["IsLotCurrentlyAvailable"] = IsLotCurrentlyAvailable; TypeOfDay = searchViewModel.TypeOfDay; ViewData["TypeOfDay"] = TypeOfDay; LotTypeID = searchViewModel.LotTypeID; ViewData["LotTypeID"] = LotTypeID; //InputPageSize = searchViewModel.InputPageSize; ViewData["InputPageSize"] = InputPageSize; } else { ViewData["IsLotCurrentlyAvailable"] = IsLotCurrentlyAvailable; ViewData["TypeOfDay"] = TypeOfDay; ViewData["LotTypeID"] = LotTypeID; ViewData["InputPageSize"] = InputPageSize; } //For test, this data will be injected with the mock data List <Lot> listOfLots = iLotRepo.ListAllLots(); //Do the searching based on user input criteria if (IsLotCurrentlyAvailable) { listOfLots = listOfLots.Where ( l => l.MaxCapacity > l.CurrentOccupancy ).ToList(); } if (TypeOfDay != null) { listOfLots = listOfLots.Where ( l => l.LotStatuses.Any(ls => ls.TypeOfDay == searchViewModel.TypeOfDay) ).ToList(); } if (LotTypeID != null) { listOfLots = listOfLots.Where ( l => l.LotStatuses.Any(ls => ls.LotTypeID == searchViewModel.LotTypeID) ).ToList(); } switch (sortOrder) { case "lotname_desc": listOfLots = listOfLots.OrderByDescending(l => l.LocationName).ToList(); ViewData["LotNameImage"] = "descending"; break; default: listOfLots = listOfLots.OrderBy(l => l.LocationName).ToList(); break; } int totalItems = listOfLots.Count(); int pageSize = InputPageSize; // from user (selecting value) //int pageNumber = 2; // from user (clicking) int excludeRows = (pageSize * pageNumber) - pageSize; listOfLots = listOfLots.Skip(excludeRows).Take(pageSize).ToList(); //Get search result (list of lots) searchViewModel.LotSearchResult.Data = listOfLots; searchViewModel.LotSearchResult.PageNumber = pageNumber; searchViewModel.LotSearchResult.PageSize = pageSize; searchViewModel.LotSearchResult.TotalItems = totalItems; return(View("SearchLots", searchViewModel)); }