Example #1
0
        public void MapperFunction_ToCountry_FunctionalityTest()
        {
            string    continentName = "Continent";
            Continent continent     = new Continent(continentName);

            string  countryName       = "Country";
            int     countryPopulation = 14000;
            float   countrySurface    = 7500.50f;
            Country country           = new Country(countryPopulation, countryName, countrySurface, continent);


            DCountry dCountry     = Mapper.ToDCountry(country);
            int      newCountryId = 10;

            dCountry.Id = newCountryId;


            Country mappedCountry = Mapper.ToCountry(dCountry, continent);

            mappedCountry.Id.Should().Be(newCountryId);
            mappedCountry.Name.Should().Be(countryName);
            mappedCountry.Surface.Should().Be(countrySurface);
            mappedCountry.Population.Should().Be(countryPopulation);
            mappedCountry.Continent.Should().Be(continent);
        }
Example #2
0
        /// <summary>
        /// Metodopara Consultar Paises
        /// </summary>


        public DataTable ConsultarCountry(string scodcountry, string snamecountry)
        {
            DCountry  odscountry = new DCountry();
            DataTable dt         = odscountry.ConsultarCountry(scodcountry, snamecountry);

            return(dt);
        }
Example #3
0
        /// <summary>
        /// Metodo para Actualizar Paises
        /// </summary>


        public ECountry ActualizarCountry(string scodcountry, string snamecountry, string slenguaje, bool bCountryDpto,
                                          bool bCountryCity, bool bDistrito, bool bBarrio, bool bstatuscountry, string sCountryModiBy, DateTime tCountryDateModiBy)
        {
            DCountry odacountry = new DCountry();
            ECountry oeacountry = odacountry.ActualizarCountry(scodcountry, snamecountry, slenguaje, bCountryDpto, bCountryCity, bDistrito,
                                                               bBarrio, bstatuscountry, sCountryModiBy, tCountryDateModiBy);

            odacountry = null;
            return(oeacountry);
        }
Example #4
0
        public void AddCountry(int continentId, string countryName, int countryPopulation, float countrySurface)
        {
            DContinent dContinent = context.Continents.Include(c => c.Countries).Single(c => c.Id == continentId);

            Continent continent = Mapper.ToContinent(dContinent);

            continent.AddCountry(new Country(countryPopulation, countryName, countrySurface, continent));

            DCountry dCountry = Mapper.ToDCountry(continent.Countries.Last());

            dContinent.Countries.Add(dCountry);
            dContinent.Population = continent.Population;
        }
Example #5
0
        public void UpdateCountry(int countryId, int continentId, string countryName, int countryPopulation, float countrySurface)
        {
            DCountry dCountry = context.Countries.Single(c => c.Id == countryId);

            Continent continent = Mapper.ToContinent(context.Continents.Single(c => c.Id == continentId));

            Country country = Mapper.ToCountry(dCountry, Mapper.ToContinent(context.Continents.Single(c => c.Id == continentId)));

            country.SetName(countryName);
            country.SetPopulation(countryPopulation);
            country.SetSurface(countrySurface);

            dCountry.Name       = country.Name;
            dCountry.Population = country.Population;
            dCountry.Surface    = country.Surface;
        }
        public void DeleteCountry(int continentId, int countryId)
        {
            if (!context.Continents.Any(c => c.Id == continentId))
            {
                throw new Exception($"Continent with id: {continentId} not in DB.");
            }
            DContinent continent = context.Continents
                                   .Include(continent => continent.Countries)
                                   .Single(c => c.Id == continentId);
            DCountry country = continent.Countries.SingleOrDefault(c => c.Id == countryId);

            if (country == null)
            {
                throw new Exception($"country with id: {countryId} not in DB.");
            }
            continent.Countries.Remove(country);
        }
        public Country GetCountry(int continentId, int countryId)
        {
            if (!context.Continents.Any(c => c.Id == continentId))
            {
                throw new Exception($"Continent with id: {continentId} not in DB.");
            }
            DContinent continent = context.Continents
                                   .Include(continent => continent.Countries)
                                   .AsNoTracking()
                                   .Single(c => c.Id == continentId);
            DCountry country = continent.Countries.SingleOrDefault(c => c.Id == countryId);

            if (country == null)
            {
                throw new Exception($"Country with id: {countryId} not in DB.");
            }
            return(Mapper.FromDCountryToCountry(country));
        }
        public void AddCountry(int continentId, Country country)
        {
            if (!context.Continents.Any(c => c.Id == continentId))
            {
                throw new Exception($"Continent with id: {continentId} not in DB.");
            }
            DContinent continent = context.Continents
                                   .Include(continent => continent.Countries)
                                   .Single(c => c.Id == continentId);

            if (continent.Countries.Any(c => c.Name == country.Name))
            {
                throw new Exception($"Country: {country.Name} already in DB.");
            }
            DCountry toAdd = Mapper.FromCountryToDCountry(country);

            if (toAdd.Id == 0)
            {
                toAdd.Id = continent.Countries.Count;
            }
            continent.Countries.Add(toAdd);
        }
        public void UpdateCountry(int continentId, int countryId, Country country)
        {
            if (!context.Continents.Any(c => c.Id == continentId))
            {
                throw new Exception($"Continent with id: {continentId} not in DB.");
            }
            DContinent continent = context.Continents
                                   .Include(continent => continent.Countries)
                                   .Single(c => c.Id == continentId);
            DCountry countryToUpdate = continent.Countries.SingleOrDefault(c => c.Id == countryId);

            if (countryToUpdate == null)
            {
                throw new Exception($"country with id: {countryId} not in DB.");
            }
            if (continent.Countries.Any(c => c.Id == country.Id))
            {
                throw new Exception($"Country with id: {country.Id} already in DB.");
            }
            countryToUpdate.Id         = (int)country.Id;
            countryToUpdate.Population = country.Population;
            countryToUpdate.Surface    = country.Surface;
            countryToUpdate.Name       = country.Name;
        }