public ActionResult NotScanned(NotScannedModel.DistributorUpdateSearchModel search, int page = 1, int pageSize = 10, GridSortOptions sort = null) { var model = new NotScannedModel(); if (search.StartDate == DateTime.MinValue) { search.StartDate = DateTime.Now.AddDays(-7); } if (search.EndDate == DateTime.MinValue) { search.EndDate = DateTime.Now; } // Search criteria model.AllDistributorUpdateTypes = _distributorService.GetAllDistributorUpdateTypeNames().Select(x => new SelectListItem() { Text = x, Value = x }).ToList().InsertEmptyValue(); model.AllWarehouses = WebUtility.ConvertDictionaryToSelectList(_warehouseService.GetAllWarehouses(), true); model.Search = search; if (Request.QueryString.HasKeys()) { // Set profile box data if (sort == null || string.IsNullOrEmpty(sort.Column)) { sort = new GridSortOptions() { Column = "DistNumber", Direction = SortDirection.Ascending } } ; ViewBag.Sort = sort; var boxes = _distributorService.SearchDistributorUpdates( new DistributorUpdateSearchCriteria { StartDate = CommonHelper.GetStartOfDate(search.StartDate), EndDate = CommonHelper.GetEndOfDate(search.EndDate), Statuses = new[] { (short)DistributorUpdateStatus.NotCompleted }, WarehouseId = search.WarehouseId, UpdateType = search.UpdateType }, page, pageSize, sort.Column, WebUtility.GetSortDir(sort)); model.DistributorUpdates = boxes.Select(x => x.ToModel <NotScannedModel.DistributorUpdateModel>()).ToList(); model.Pager = boxes.ToMvcPaging(model.DistributorUpdates); // If current page > total pages, redirect to last page if (model.Pager.TotalPages > 0 && model.Pager.PageNumber > model.Pager.TotalPages) { return(Redirect(Url.Paging(model.Pager.TotalPages, model.Pager.PageSize).ToString())); } } return(View(model)); }