public async Task <IActionResult> EditLocation(LocationsListViewModel model) { if (!string.IsNullOrWhiteSpace(model.Location.Url)) { try { model.Location.Url = new UriBuilder( model.Location.Url).Uri.AbsoluteUri; } catch (Exception) { ShowAlertDanger("Invalid URL"); return(RedirectToAction("Locations")); } } if (ModelState.IsValid) { try { await _eventService.EditLocation(model.Location); ShowAlertSuccess($"Location '{model.Location.Name}' updated"); } catch (GraException gex) { ShowAlertDanger("Unable to edit Location: ", gex); } } return(RedirectToAction("Locations")); }
public IActionResult All(string searchString, string filter, int page = 1) { this.ViewData["CurrentFilter"] = filter; this.ViewData["CurrentSearchString"] = searchString; var viewModel = new LocationsListViewModel(); var count = this.locationsService.GetLocationsCount(); viewModel.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage); var locations = this.locationsService.GetAll <LocationsListItemViewModel>(ItemsPerPage, (page - 1) * ItemsPerPage); if (!string.IsNullOrEmpty(filter)) { locations = locations.Where(l => l.Type == filter); } if (!string.IsNullOrEmpty(searchString)) { locations = locations.Where(l => l.Name.ToLower().Contains(searchString.ToLower()) || l.Description.ToLower().Contains(searchString.ToLower())); } viewModel.Locations = locations; if (viewModel.PagesCount == 0) { viewModel.PagesCount = 1; } viewModel.CurrentPage = page; return(this.View(viewModel)); }
public async Task <IActionResult> Locations(int page = 1) { BaseFilter filter = new BaseFilter(page); var locationList = await _eventService.GetPaginatedLocationsListAsync(filter); PaginateViewModel paginateModel = new PaginateViewModel() { ItemCount = locationList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.MaxPage > 0 && paginateModel.CurrentPage > paginateModel.MaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } LocationsListViewModel viewModel = new LocationsListViewModel() { Locations = locationList.Data, PaginateModel = paginateModel, }; return(View(viewModel)); }
public async Task <IActionResult> SearchLocationsAsync(SearchLocationsViewModel searchModel) { try { LocationSearchDto searchDto = new LocationSearchDto { Title = searchModel.Title }; var locations = await locationService.SearchLocationsAsync(searchDto); LocationsListViewModel viewModel = new LocationsListViewModel() { Locations = locations }; return(View("Views/Location/LocationsList.cshtml", viewModel)); } catch (Exception ex) { ErrorViewModel errorModel = new ErrorViewModel(); errorModel.ErrorMessage = ex.Message.ToString(); return(View("Views/Shared/Error.cshtml", errorModel)); } }
public async Task <IActionResult> Index() { var locations = new LocationsListViewModel() { Locations = await this.countriesService.GetAll <LocationsIndexViewModel>(), }; return(this.View(locations)); }
public void Load() { ReloadButtonEnabled = false; ProgressPercentage = 0; ProgressBarVisibility = Visibility.Visible; FeaturesListViewModel.Load(); LocationsListViewModel.Load(); }
public ViewResult List(int page = 1) { var locationsListViewModel = new LocationsListViewModel(); locationsListViewModel.Locations = locations.GetLocations(page, PageSize); locationsListViewModel.PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = locations.GetLocationsCount() }; return(View(locationsListViewModel)); }
public async Task <IActionResult> LocationsListAsync() { try { var locations = await locationService.GetAsync(); var model = new LocationsListViewModel() { Locations = locations }; return(View("Views/Location/LocationsList.cshtml", model)); } catch (Exception ex) { ErrorViewModel errorModel = new ErrorViewModel(); errorModel.ErrorMessage = ex.Message.ToString(); return(View("Views/Shared/Error.cshtml", errorModel)); } }
public void Location_Can_Send_Pagination() { // Arrange Mock <ILogger <LocationsController> > mockLogger = new Mock <ILogger <LocationsController> >(); Mock <ILocationRepository> mockLocationRepository = new Mock <ILocationRepository>(); mockLocationRepository.Setup(m => m.GetLocations).Returns((new Location[] { new Location { LocationId = 1, ParentId = 0, Description = "L1" }, new Location { LocationId = 2, ParentId = 1, Description = "L2" }, new Location { LocationId = 3, ParentId = 1, Description = "L3" }, new Location { LocationId = 4, ParentId = 1, Description = "L4" }, new Location { LocationId = 5, ParentId = 1, Description = "L5" } }).AsQueryable <Location>()); LocationsController controller = new LocationsController(mockLogger.Object, mockLocationRepository.Object); controller.PageSize = 3; // Act LocationsListViewModel result = controller.List(2).ViewData.Model as LocationsListViewModel; // Assert PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(2, pageInfo.CurrentPage); Assert.AreEqual(3, pageInfo.ItemsPerPage); Assert.AreEqual(5, pageInfo.TotalItems); Assert.AreEqual(2, pageInfo.TotalPages); }
public void Location_Can_Paginate() { // Arrange Mock <ILogger <LocationsController> > mockLogger = new Mock <ILogger <LocationsController> >(); Mock <ILocationRepository> mockLocationRepository = new Mock <ILocationRepository>(); mockLocationRepository.Setup(m => m.GetLocations).Returns((new Location[] { new Location { LocationId = 1, ParentId = 0, Description = "L1" }, new Location { LocationId = 2, ParentId = 1, Description = "L2" }, new Location { LocationId = 3, ParentId = 1, Description = "L3" }, new Location { LocationId = 4, ParentId = 1, Description = "L4" }, new Location { LocationId = 5, ParentId = 1, Description = "L5" } }).AsQueryable <Location>()); LocationsController controller = new LocationsController(mockLogger.Object, mockLocationRepository.Object); controller.PageSize = 3; // Act LocationsListViewModel result = controller.List(2).ViewData.Model as LocationsListViewModel; // Assert Location[] LocationArray = result.Locations.ToArray(); Assert.IsTrue(LocationArray.Length == 2); Assert.AreEqual("L4", LocationArray[0].Description); Assert.AreEqual("L5", LocationArray[1].Description); }
public LocationsListPage() { InitializeComponent(); locationsHolder = new LocationsListViewModel(); BindingContext = locationsHolder; }