Beispiel #1
0
        public async Task <ActionResult> AddorEdit([Bind("Name, CountryCode, District, Population")] City city)
        {
            var context     = new worldContext();
            var currentCity = context.City.Where(c => c.Name.Equals(city.Name)).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (currentCity == null)
                {
                    context.Add(city);
                }
                else
                {
                    currentCity.Name        = city.Name;
                    currentCity.CountryCode = city.CountryCode;
                    currentCity.District    = city.District;
                    currentCity.Population  = city.Population;
                    context.Update(currentCity);
                }
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
 public async Task <IEnumerable <City> > GetCitiesAsync()
 {
     using (var context = new worldContext())
     {
         return(await context.City.Include(x => x.CountryCodeNavigation).ToListAsync());
     }
 }
 public async Task <IEnumerable <Country> > GetCountriesAsync()
 {
     using (var context = new worldContext())
     {
         return(await context.Country.ToListAsync());
     }
 }
        public async Task CreateCityAsync(City city)
        {
            using (var context = new worldContext())
            {
                await context.City.AddAsync(city);

                context.SaveChanges();
            }
        }
        public async Task <City> GetCityDetailsAsync(int cityId)
        {
            using (var context = new worldContext())
            {
                var countryQuery = context.City.Include(db => db.CountryCodeNavigation);
                var details      = await countryQuery.SingleOrDefaultAsync(x => x.Id == cityId);

                return(details);
            }
        }
        public async Task <Country> GetCountryDetailsAsync(string countryCode)
        {
            using (var context = new worldContext())
            {
                var countryQuery = context.Country.Include(db => db.City);
                var details      = await countryQuery.SingleOrDefaultAsync(x => x.Code == countryCode);

                return(details);
            }
        }
 public async Task UpdateCityAsync(City city)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             context.City.Update(city);
             context.SaveChanges();
         }
     });
 }
 public async Task UpdateCountryAsync(Country country)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             context.Country.Update(country);
             context.SaveChanges();
         }
     });
 }
        static void Main(string[] args)
        {
            worldContext context     = new worldContext();
            ICity        cityService = new CityService(context);

            // this is example of various testing scenarios

            // cityService.AddCity(new City(5000, "markov grad", "markovija", 2, "PSE"));
            // cityService.UpdateCity(5001, "markov promijenjeni grad", "markovija", 5, "PSE");
            // cityService.DeleteCity(5001);
            // List<City> cities = cityService.FindCities("", "", 12000, "");
        }
Beispiel #10
0
        // GET: CountryController
        public ActionResult Index()
        {
            var context = new worldContext();
            var list    = context.Country.ToList();
            var list2   = new List <Country>();

            foreach (Country country in list)
            {
                country.NationalFlag = convertPath(country);
                list2.Add(country);
            }
            return(View(list2));
        }
Beispiel #11
0
        public ActionResult AddorEdit(string id)
        {
            var context = new worldContext();

            if (id == null || id.Length == 0)
            {
                return(View(new Country()));
            }
            else
            {
                return(View(context.Country.Find(id)));
            }
        }
Beispiel #12
0
        // GET: CountryController/Delete/5
        public ActionResult Delete(string id)
        {
            var context = new worldContext();

            if (id == null)
            {
                return(NotFound());
            }
            var country = context.Country.FirstOrDefault(c => c.Code.Equals(id));

            context.Country.Remove(country);
            context.SaveChanges();
            return(RedirectToAction(nameof(Index)));
        }
Beispiel #13
0
        public ActionResult AddorEdit(int id)
        {
            var context = new worldContext();

            if (id == 0)
            {
                ViewBag.ListCountry = context.Country.ToList();
                return(View(new City()));
            }
            else
            {
                ViewBag.ListCountry = context.Country.ToList();
                return(View(context.City.Find(id)));
            }
        }
 public async Task RemoveCityByIdAsync(int id)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             var cityToDelete = new City {
                 Id = id
             };
             context.City.Attach(cityToDelete);
             context.City.Remove(cityToDelete);
             context.SaveChanges();
         }
     });
 }
 public async Task RemoveCountryByCodeAsync(string code)
 {
     await Task.Run(() =>
     {
         using (var context = new worldContext())
         {
             var countryToDelete = new Country {
                 Code = code
             };
             context.Country.Attach(countryToDelete);
             context.Country.Remove(countryToDelete);
             context.SaveChanges();
         }
     });
 }
Beispiel #16
0
        // GET: CityController/Delete/5
        public ActionResult Delete(int id)
        {
            var context = new worldContext();

            if (id == 0)
            {
                return(NotFound());
            }
            var city = context.City.FirstOrDefault(c => c.Id.Equals(id));

            if (city == null)
            {
                return(NotFound());
            }

            return(View(city));
        }
Beispiel #17
0
        // GET: CountryController/Details/5
        public ActionResult Detail(string id)
        {
            var context = new worldContext();

            if (id == null)
            {
                return(NotFound());
            }
            var country = context.Country.FirstOrDefault(c => c.Code.Equals(id));

            country.NationalFlag = convertPath(country);
            if (country == null)
            {
                return(NotFound());
            }

            return(View(country));
        }
Beispiel #18
0
 public ActionResult Delete(int?id)
 {
     try
     {
         var context = new worldContext();
         if (id == 0)
         {
             return(NotFound());
         }
         var city = context.City.FirstOrDefault(c => c.Id == id);
         context.City.Remove(city);
         context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #19
0
        public async Task <ActionResult> AddorEdit([Bind("Code, Name, Region, NationalFlag")] Country country)
        {
            var context        = new worldContext();
            var currentCountry = context.Country.Find(country.Code);

            if (ModelState.IsValid)
            {
                if (currentCountry == null)
                {
                    context.Add(country);
                }
                else
                {
                    currentCountry.Name         = country.Name;
                    currentCountry.Region       = country.Region;
                    currentCountry.NationalFlag = country.NationalFlag;
                    context.Update(currentCountry);
                }
                await context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
Beispiel #20
0
 public CountryService(worldContext ctx)
 {
     context = ctx;
 }
Beispiel #21
0
 public CityController()
 {
     _contextCity = new worldContext();
 }
 public CityController(worldContext context)
 {
     _context = context;
 }
Beispiel #23
0
 public CityController(worldContext context)
 {
     _context     = context;
     _cityService = new CityService(context);
 }
 public CityService(worldContext ctx)
 {
     context = ctx;
 }
 public CountryController()
 {
     _context = new worldContext();
 }
Beispiel #26
0
        // GET: CityController
        public ActionResult Index()
        {
            var context = new worldContext();

            return(View(context.City.ToList()));
        }
 public CityRepository(worldContext context)
 {
     _context = context;
 }
 public CountrylanguageService(worldContext ctx)
 {
     context = ctx;
 }
 public CountryController(worldContext context)
 {
     _context = context;
 }
 public CountryController(worldContext db)
 {
     _db = db;
 }