public IActionResult GetAll()
 {
     try
     {
         return(Ok(_citiesService.GetAll()));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public async Task GetAllGenericShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetAllGenericCities").Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Cities.Add(new City());
            dbContext.Cities.Add(new City());
            dbContext.Cities.Add(new City());
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <City>(dbContext);
            var service    = new CitiesService(repository);

            Assert.Equal(3, service.GetAll <City>().Count());
        }
        public async Task TestGetAllCities()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase("Cities");

            var cityRepository = new EfDeletableEntityRepository <City>(new ApplicationDbContext(options.Options));

            await cityRepository.AddAsync(new City { Name = "София" });

            await cityRepository.AddAsync(new City { Name = "Стара Загора" });

            await cityRepository.AddAsync(new City { Name = "Пловдив" });

            await cityRepository.SaveChangesAsync();

            var cityService = new CitiesService(cityRepository);

            AutoMapperConfig.RegisterMappings(typeof(MyTestCity).Assembly);
            var cities = cityService.GetAll <MyTestCity>();

            Assert.Equal(3, cities.Count());
        }
        public ActionResult List()
        {
            CitiesService citiesService = new CitiesService();

            CitiesListVM model = new CitiesListVM();
            TryUpdateModel(model);

            model.Cities = citiesService.GetAll();

            if (!String.IsNullOrEmpty(model.Search))
            {
                model.Cities = model.Cities.Where(c => c.Name.ToLower().Contains(model.Search.ToLower())).ToList();
            }

            switch (model.SortOrder)
            {
                case "country_asc":
                    model.Cities = model.Cities.OrderBy(c => c.Country.Name).ToList();
                    break;
                case "country_desc":
                    model.Cities = model.Cities.OrderByDescending(c => c.Country.Name).ToList();
                    break;
                case "postcode_asc":
                    model.Cities = model.Cities.OrderBy(c => c.PostCode).ToList();
                    break;
                case "postcode_desc":
                    model.Cities = model.Cities.OrderByDescending(c => c.PostCode).ToList();
                    break;
                case "name_desc":
                    model.Cities = model.Cities.OrderByDescending(c => c.Name).ToList();
                    break;
                case "name_asc":
                default:
                    model.Cities = model.Cities.OrderBy(c => c.Name).ToList();
                    break;
            }

            return View(model);
        }