Beispiel #1
0
        public void Create(CountryDisplayModel entity)
        {
            var country = new Country()
            {
                Name       = entity.Name,
                Code       = entity.Alpha3Code,
                Area       = entity.Area,
                Population = entity.Population
            };

            var capital = _context.Cities.SingleOrDefault(city => city.Name == entity.Capital);

            if (capital == null)
            {
                capital = new City()
                {
                    Name = entity.Capital
                };
                _context.Cities.Add(capital);
                _context.SaveChanges();
            }
            country.Capital = capital;

            var region = _context.Regions.SingleOrDefault(r => r.Name == entity.Region);

            if (region == null)
            {
                region = new Region()
                {
                    Name = entity.Region
                };
                _context.Regions.Add(region);
                _context.SaveChanges();
            }
            country.Region = region;

            var savedCountry = _context.Countries.SingleOrDefault(c => c.Code == entity.Alpha3Code);

            if (savedCountry != null)
            {
                Update(savedCountry);
            }
            else
            {
                Create(country);
            }

            _context.SaveChanges();
        }
Beispiel #2
0
 public ActionResult Save(CountryDisplayModel country)
 {
     _countryRepository.Create(country);
     return(RedirectToAction("List"));
 }
Beispiel #3
0
 public void Update(CountryDisplayModel entity)
 {
     throw new System.NotImplementedException();
 }