Beispiel #1
0
        public static void DeleteCountry()
        {
            Guid countryId = SetInformations.SetCountryId();

            using (var dataService = new TableDataService <Country>())
            {
                dataService.DeleteById(countryId);
            }
        }
Beispiel #2
0
        public static void UpdateCity(Guid cityId, CityProperties property)
        {
            if (cityId != Guid.Empty)
            {
                switch (property)
                {
                case CityProperties.Name:
                    string newName = SetInformations.SetName();
                    using (var dataService = new TableDataService <City>())
                    {
                        var chosenCity = dataService.GetAll().Where(city => city.Id == cityId).SingleOrDefault();
                        dataService.DeleteById(cityId);
                        chosenCity.Name = newName;
                        dataService.Add(chosenCity);
                    }
                    break;

                case CityProperties.Population:
                    int newPopulation = SetInformations.SetPopulation();
                    using (var dataService = new TableDataService <City>())
                    {
                        var chosenCity = dataService.GetAll().Where(city => city.Id == cityId).SingleOrDefault();
                        dataService.DeleteById(cityId);
                        chosenCity.Population = newPopulation;
                        dataService.Add(chosenCity);
                    }
                    break;

                case CityProperties.CountryId:
                    Guid newCountryId = SetInformations.SetCountryId();
                    if (newCountryId != Guid.Empty)
                    {
                        using (var dataService = new TableDataService <City>())
                        {
                            var chosenCity = dataService.GetAll().Where(city => city.Id == cityId).SingleOrDefault();
                            dataService.DeleteById(cityId);
                            chosenCity.CountryId = newCountryId;
                            dataService.Add(chosenCity);
                        }
                    }
                    break;
                }
            }
        }
Beispiel #3
0
        public static void AddCity()
        {
            City newCity = new City()
            {
                Name       = SetInformations.SetName(),
                Population = SetInformations.SetPopulation(),
                CountryId  = SetInformations.SetCountryId()
            };

            using (var dataService = new TableDataService <City>())
            {
                if (newCity.Id != Guid.Empty)
                {
                    if (!dataService.GetAll().Any(city => city.Name.ToLower() == newCity.Name.ToLower() && city.Population == newCity.Population && city.CountryId == newCity.CountryId))
                    {
                        dataService.Add(newCity);
                    }
                }
            }
        }