public virtual IActionResult ExportExcelAll(TripSearchModel searchModel) { if (!permissionService.Authorize(StandardPermissionProvider.ManageTrips)) { return(AccessDeniedView()); } var list = tripService.GetAll( carLicense: searchModel.SearchCarLicense, driverName: searchModel.SearchDriverName, serialNum: searchModel.SearchSerialNum, shippingStatuses: (searchModel.SearchShippingStatuses?.Contains(0) ?? false) ? null : searchModel.SearchShippingStatuses, startAtFrom: searchModel.SearchStartAtFrom, startAtTo: searchModel.SearchStartAtTo, endAtFrom: searchModel.SearchEndAtFrom, endAtTo: searchModel.SearchEndAtTo); try { var bytes = exportManager.ExportTripToXlsx(list); return(File(bytes, MimeTypes.TextXlsx, $"{localizationService.GetResource("Admin.Logistics.Trip")}.xlsx")); } catch (Exception ex) { ErrorNotification(ex); return(RedirectToAction("List")); } }
public virtual TripListModel PrepareListModel(TripSearchModel searchModel) { if (null == searchModel) { throw new ArgumentNullException(nameof(searchModel)); } var list = tripService.GetAll( pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize, carLicense: searchModel.SearchCarLicense, driverName: searchModel.SearchDriverName, serialNum: searchModel.SearchSerialNum, shippingStatuses: (searchModel.SearchShippingStatuses?.Contains(0) ?? false) ? null : searchModel.SearchShippingStatuses, startAtFrom: searchModel.SearchStartAtFrom, startAtTo: searchModel.SearchStartAtTo, endAtFrom: searchModel.SearchEndAtFrom, endAtTo: searchModel.SearchEndAtTo); var model = new TripListModel { Data = list.Select(x => { var modelItem = x.ToModel <TripModel>(); PrepareModel(ref modelItem); return(modelItem); }), Total = list.TotalCount }; return(model); }
private IQueryable <Trip> GetTrips(TripSearchModel searchModel) { var result = db.Trips.AsQueryable(); if (searchModel != null) { if (!string.IsNullOrEmpty(searchModel.TitleKeyword)) { result = result.Where(t => t.Title.Contains(searchModel.TitleKeyword)); } if (searchModel.TripCategory.HasValue) { result = result.Where(t => t.TripCategory == searchModel.TripCategory); } if (!string.IsNullOrEmpty(searchModel.Country)) { result = result.Where(t => t.Country == searchModel.Country); } if (searchModel.MinDuration.HasValue) { result = result.Where(t => t.Duration >= searchModel.MinDuration); } if (searchModel.MaxDuration.HasValue) { result = result.Where(t => t.Duration <= searchModel.MaxDuration); } } return(result.OrderByDescending(t => t.Duration)); }
public async Task <ActionResult> Search(TripSearchModel searchModel) { List <Trip> trips = await GetTrips(searchModel).ToListAsync(); ViewBag.PreviousSearch = searchModel; ViewBag.CountryList = Trip.GetCountries(); return(View(trips)); }
public virtual IActionResult List(TripSearchModel searchModel) { if (!permissionService.Authorize(StandardPermissionProvider.ManageTrips)) { return(AccessDeniedView()); } var model = tripFactory.PrepareListModel(searchModel); return(Json(model)); }
public virtual TripSearchModel PrepareSearchModel(TripSearchModel searchModel) { if (null == searchModel) { throw new ArgumentNullException(nameof(searchModel)); } baseAdminModelFactory.PrepareLogisticsShippingStatus(searchModel.AvailableShippingStatuses); searchModel.SetGridPageSize(); return(searchModel); }
public async Task CanSearchTrip() { // Arrange - create the mock repository TestTrekStoriesContext tc = new TestTrekStoriesContext(); Trip trip1 = new Trip { Title = "Trip 1", StartDate = new DateTime(2015, 4, 12), TripOwner = "ABC123", TripCategory = TripCategory.architecture }; Trip trip2 = new Trip { Title = "Trip 2", StartDate = new DateTime(2015, 4, 13), TripOwner = "ABC123", TripCategory = TripCategory.forest }; Trip trip3 = new Trip { Title = "Another Title", StartDate = new DateTime(2015, 4, 16), TripOwner = "ABC123" }; Trip trip4 = new Trip { Title = "Trip 4", StartDate = new DateTime(2018, 4, 16), TripOwner = "AnotherUser", TripCategory = TripCategory.architecture }; tc.Trips.Add(trip1); tc.Trips.Add(trip2); tc.Trips.Add(trip3); tc.Trips.Add(trip4); // Arrange - create a controller var controller = new TripController(tc); // Action TripSearchModel searchModel = new TripSearchModel { TripCategory = TripCategory.architecture, TitleKeyword = "Trip" }; var viewResult = await controller.Search(searchModel) as ViewResult; List <Trip> result = (List <Trip>)viewResult.ViewData.Model; // Assert - ordered descending + only show trips from ABC123 Assert.AreEqual(2, result.Count); CollectionAssert.Contains(result, trip1); CollectionAssert.Contains(result, trip4); }