Ejemplo n.º 1
0
        public ActionResult Index(string search = "")
        {
            var           model   = new List <RegionViewModel>();
            List <Region> regions = string.IsNullOrWhiteSpace(search) ? _regionRepository.GetAll() : _regionRepository.FindRegions(search);

            foreach (Region region in regions)
            {
                var regionViewModel = new RegionViewModel
                {
                    Id        = region.Id,
                    Name      = region.Name,
                    Locations = new List <LocationViewModel>()
                };

                foreach (var location in region.Locations) // <-- alltid tom lista? ta bort.
                {
                    regionViewModel.Locations.Add(new LocationViewModel()
                    {
                        Id   = location.Id,
                        Name = location.Name
                    });
                }

                model.Add(regionViewModel);
            }

            ViewBag.SearchString = search;
            return(View(model));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets region paginated list
 /// </summary>
 /// <param name="searchViewModel">holds the search parameter</param>
 /// <returns>Paginated List</returns>
 public async Task <Extensions.PaginatedList <Region> > FindRegions(RegionSearchViewModel searchViewModel)
 {
     return(await _regionRepository.FindRegions(searchViewModel));
 }