コード例 #1
0
 public ActionResult <CountryInApi> PostCountry(int continentId, [FromBody] CountryInApi countryInApi)
 {
     logger.LogInformation($"Post api/continent/{continentId}/country/ called");
     try
     {
         Domain.Models.Country country        = CountryMapper.CountryInMapper(continentManager, countryInApi);
         Domain.Models.Country countryCreated = countryManager.AddCountry(country);
         if (countryCreated != null)
         {
             CountryOutApi countryOut = CountryMapper.CountryOutMapper(hostUrl, countryCreated);
             return(CreatedAtAction(nameof(GetCountry), new
             {
                 continentId = countryCreated.Continent.Id,
                 countryId = countryCreated.Id
             }, countryOut));
         }
         else
         {
             logger.LogError("Country can not be null.");
             return(NotFound("Country can not be null."));
         }
     }
     catch (Exception ex)
     {
         logger.LogError(ex.Message);
         return(NotFound(ex.Message));
     }
 }
コード例 #2
0
        private static void Main(string[] args)
        {
            ContinentManager continentManager = new ContinentManager(new UnitOfWork());
            CountryManager   countryManager   = new CountryManager(new UnitOfWork());

            Continent continent1       = new Continent("Antartica");
            Continent continent2       = new Continent("Europe");
            Continent continent1WithId = continentManager.AddContinent(continent1);
            Continent continent2WithId = continentManager.AddContinent(continent2);
            Country   country1         = new Country("Tuvalu", 11792, 30, continent1WithId);
            Country   country2         = new Country("Nauru", 10824, 20, continent1WithId);

            countryManager.AddCountry(country1);
            countryManager.AddCountry(country2);
        }
コード例 #3
0
        public async Task Task_UpdateCountry_OkResult()
        {
            var country = new CountryModel
            {
                CountryId = 5,
                Name      = "Nigeria",
                Continent = "Africa",
                //DateCreated = DateTime.Now
            };

            //Arrange
            var options = new DbContextOptionsBuilder <CountryData>()
                          .UseInMemoryDatabase(databaseName: "Get_Countries")
                          .Options;


            // Run the test against one instance of the context
            using (var context = new CountryData(options))
            {
                var repository   = new CountryRepository(context);
                var modelmanager = new CountryManager(repository);



                //Act
                await modelmanager.AddCountry(country);

                var result = await modelmanager.GetAllCountries();

                //Assert

                Assert.AreEqual(country.Name, result[0].Name);
            }
        }
コード例 #4
0
        public async Task RepoCreateandGetCountryFoUser()
        {
            //Arrange
            var userId  = "8742954e-0993-4498-bea5-5b3d60857a86";
            var country = new CountryModel
            {
                CountryId = 10,
                Name      = "Nigeria",
                Continent = "Africa",
                //DateCreated = DateTime.Now
            };

            var options = new DbContextOptionsBuilder <CountryData>()
                          .UseInMemoryDatabase(databaseName: "Get_Countries")
                          .Options;

            // Run the test against one instance of the context
            using (var context = new CountryData(options))
            {
                var repository   = new CountryRepository(context);
                var modelmanager = new CountryManager(repository);

                //Act
                await modelmanager.AddCountry(country);

                var result = await modelmanager.GetAllCountries();

                //Assert
                Assert.AreEqual(country.Name, result[0].Name);
            }
        }
コード例 #5
0
 public IActionResult Create(Country country)
 {
     if (ModelState.IsValid)
     {
         countryManager.AddCountry(country);
         TempData["message"] = "Se ha agregado país correctamente";
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #6
0
 public long AddCountry(CountryObject country)
 {
     try
     {
         return(_countryManager.AddCountry(country));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
コード例 #7
0
 // Dodaje novu državu
 //[Authorize(Roles ="Administrator")]
 public ActionResult AddCountry(CountryVM c)
 {
     if (!User.IsInRole("Administrator"))
     {
         return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
     }
     else if (ModelState.IsValid)
     {
         CountryManager.AddCountry(c);
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     return(new HttpStatusCodeResult(HttpStatusCode.NotModified));
 }
コード例 #8
0
        private void SaveCountryButton_Click(object sender, EventArgs e)
        {
            if (CountryCodeTextBox.Text != string.Empty)
            {
                //Create a new country entry
                Country country = new Country();
                country.Name = CountryNameTextBox.Text;

                //call the method in ColoursMaanger to save the data
                Country saveCountry = CountryManager.AddCountry(country);

                //create a message to indicate it was successful
                MessageBox.Show("A new country has been added.");

                //refresh the list to display the new information
                List <Country> countriesList = CountryManager.GetCountryList();
                CountryListBox.DataSource = countriesList;

                //select the new colour from the list
                SelectCountryFromListBox(saveCountry.CountryCode);
            }
            else
            {
                //Save changes to an existing item
                //get the selected country code and the name from the text boxes
                string countryCode = CountryCodeTextBox.Text;
                string countryName = CountryNameTextBox.Text;

                //execute the update from ColoursManager
                //then check the result
                //Converted the 1 from an int to a string
                int    num       = 1;
                string stringNum = num.ToString();

                if (CountryManager.UpdateCountry(countryCode, countryName) == stringNum)
                {
                    //create a message to indicate update was successful
                    MessageBox.Show("Country has been Updated");

                    //refresh the list to show the updated values
                    List <Country> countryList = CountryManager.GetCountryList();
                    CountryListBox.DataSource = countryList;
                }
                else
                {
                    //create a message to indicate update was NOT successful
                    MessageBox.Show("Country NOT updated.");
                }
            }
        }
コード例 #9
0
        public void AddContinent_ShouldAddContinentAndUpdateCountries_IfContinentIsValid()
        {
            // Arrange
            Continent      continent1     = new Continent("Africa");
            Continent      continent1InDb = continentManager.AddContinent(continent1);
            Country        country1       = new Country("Afghanistan", 38928346, 652.860, continent1InDb);
            Country        country2       = new Country("Albania", 2877797, 27.400, continent1InDb);
            Country        country1InDb   = countryManager.AddCountry(country1);
            Country        country2nDb    = countryManager.AddCountry(country2);
            List <Country> countries      = new List <Country>();

            countries.Add(country1InDb); countries.Add(country2nDb);
            Continent continent2 = new Continent("Asia", countries);

            // Act
            continentManager.AddContinent(continent2);
            Continent continent2InDb = continentManager.Find("Asia");

            // Assert
            continent2InDb.Should().BeEquivalentTo(continent2, options => options.Excluding(o => o.Id));
        }