Exemplo n.º 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();
         }
     });
 }
Exemplo n.º 9
0
        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, "");
        }
Exemplo n.º 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));
        }
Exemplo n.º 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)));
            }
        }
Exemplo n.º 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)));
        }
Exemplo n.º 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();
         }
     });
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 20
0
 public CountryService(worldContext ctx)
 {
     context = ctx;
 }
Exemplo n.º 21
0
 public CityController()
 {
     _contextCity = new worldContext();
 }
Exemplo n.º 22
0
 public CityController(worldContext context)
 {
     _context = context;
 }
Exemplo n.º 23
0
 public CityController(worldContext context)
 {
     _context     = context;
     _cityService = new CityService(context);
 }
Exemplo n.º 24
0
 public CityService(worldContext ctx)
 {
     context = ctx;
 }
Exemplo n.º 25
0
 public CountryController()
 {
     _context = new worldContext();
 }
Exemplo n.º 26
0
        // GET: CityController
        public ActionResult Index()
        {
            var context = new worldContext();

            return(View(context.City.ToList()));
        }
Exemplo n.º 27
0
 public CityRepository(worldContext context)
 {
     _context = context;
 }
 public CountrylanguageService(worldContext ctx)
 {
     context = ctx;
 }
Exemplo n.º 29
0
 public CountryController(worldContext context)
 {
     _context = context;
 }
Exemplo n.º 30
0
 public CountryController(worldContext db)
 {
     _db = db;
 }