예제 #1
0
        private void DeleteCountryButton_Click(object sender, EventArgs e)
        {
            string countryCode  = CountryCodeTextBox.Text;
            int    rowsAffected = Convert.ToInt32(CountryManager.DeleteCountry(countryCode));

            if (rowsAffected == 1)
            {
                MessageBox.Show(
                    "Country deleted.",
                    "Deleted",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(
                    "Unable to delete country.",
                    "Unable to delete.",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                //refresh the list with the updated information
                CountryListBox.DataSource = CountryManager.GetCountryList();
            }
        }
예제 #2
0
        public async Task Task_DeleteCountry_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.DeleteCountry(country.CountryId);

                var result = await modelmanager.GetAllCountries();

                //Assert

                Assert.AreEqual(country.Name, result[0].Name);
            }
        }
    protected void lbDelete_Click(object sender, EventArgs e)
    {
        LinkButton linkButton = new LinkButton();

        linkButton = (LinkButton)sender;
        bool result = CountryManager.DeleteCountry(Convert.ToInt32(linkButton.CommandArgument));

        showCountryGrid();
    }
예제 #4
0
 protected void DeleteButton_Click(object sender, EventArgs e)
 {
     try
     {
         CountryManager.DeleteCountry(this.CountryID);
         Response.Redirect("Countries.aspx");
     }
     catch (Exception exc)
     {
         ProcessException(exc);
     }
 }
예제 #5
0
 public long DeleteCountry(long countryId)
 {
     try
     {
         return(_countryManager.DeleteCountry(countryId));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
예제 #6
0
        public IActionResult DeleteCountry(int?id)
        {
            var country = countryManager.FindById((int)id);

            if (country == null)
            {
                return(NotFound());
            }

            countryManager.DeleteCountry((int)id);
            TempData["message"] = "Se ha eliminado país correctamente";
            return(RedirectToAction("Index"));
        }
예제 #7
0
        static void Main(string[] args)
        {
            #region "GET ALL"

            #region "GET ALL Currencies TEST"

            List <Currency> currenciesList = CurrencyManager.GetCurrencyList();
            Console.WriteLine("List of currencies: " + "\n");

            foreach (Currency currency in currenciesList)
            {
                Console.WriteLine(currency.Name);
            }

            #endregion
            #region "GET ALL Colours TEST"

            List <Colour> coloursList = ColoursManager.GetColourList();
            Console.WriteLine("\nList of colours: ");

            foreach (Colour colour in coloursList)
            {
                Console.WriteLine(colour.Name);
            }

            #endregion
            #region "GET ALL Country TEST"
            List <Country> countriesList = CountryManager.GetCountryList();
            Console.WriteLine("\nList of countries: ");

            foreach (Country country in countriesList)
            {
                Console.WriteLine(country.Name);
            }
            #endregion
            #region "GET ALL Types TEST"
            List <Type> typesList = TypesManager.GetTypeList();
            Console.WriteLine("\nList of types: ");

            foreach (Type type in typesList)
            {
                Console.WriteLine(type.Name);
            }

            #endregion
            #endregion
            #region "GET ONE"
            #region "GET ONE Currency by ID TEST"
            Console.Write("\nEnter a currency ID: ");
            string getCurrencyId = Console.ReadLine();

            Currency getCurrencyById = CurrencyManager.GetCurrency(int.Parse(getCurrencyId));

            if (getCurrencyById != null)
            {
                Console.WriteLine(getCurrencyById.Name);
            }
            else
            {
                Console.WriteLine("Sorry, currency ID cannot be found.");
            }
            #endregion
            #region "GET ONE Colours by ID TEST"

            Console.Write("\nEnter a Colour ID: ");
            string getColourId = Console.ReadLine();

            Colour getColourById = ColoursManager.GetColour(int.Parse((getColourId)));

            if (getColourById != null)
            {
                Console.WriteLine(getColourById.Name);
            }
            else
            {
                Console.WriteLine("Sorry, the colour ID cannot be found.");
            }
            #endregion
            #region "GET ONE Country by ID TEST"

            Console.Write("\nEnter a country Code: ");
            string getCountryCode = Console.ReadLine();

            Country getCountryByCode = CountryManager.GetCountry(getCountryCode);

            if (getCountryByCode != null)
            {
                Console.WriteLine(getCountryByCode.Name);
            }
            else
            {
                Console.WriteLine("Sorry, the country code cannot be found.");
            }
            #endregion
            #region "GET ONE Type by ID TEST"

            Console.Write("\nEnter a type ID: ");
            string getTypeId = Console.ReadLine();

            Type getTypeById = TypesManager.GetTypes(int.Parse((getTypeId)));

            if (getTypeById != null)
            {
                Console.WriteLine(getTypeById.Name);
            }
            else
            {
                Console.WriteLine("Sorry, the type ID cannot be found.");
            }

            #endregion
            #endregion

            #region "ADD"

            /*
             #region "ADD Currency TEST"
             * Currency addCurrency = new Currency();
             * addCurrency.Name = "Japanese Yen";
             *
             * Currency addCurrencyTwo = CurrencyManager.AddCurrency(addCurrency);
             * Console.WriteLine(string.Format("The new Currency ID is {0}", addCurrency.Id));
             */
            #region "ADD Colour TEST"
            Colour addColour = new Colour();
            addColour.Id   = 20;
            addColour.Name = "Blue";

            Colour addColourTwo = ColoursManager.AddColour(addColour);
            Console.WriteLine(string.Format("The new Colour Id is {0}", addColourTwo.Id));
            #endregion

            #region "ADD Country TEST"
            #endregion

            #region "ADD Type TEST"
            #endregion

            #endregion

            #region "UPDATE"

            /*
             #region "UPDATE Currency TEST"
             * Currency updateCurrency = new Currency();
             * updateCurrency.Id = 3;
             * updateCurrency.Name = "Japanese Yen";
             * updateCurrency.ColourId = 4;
             * updateCurrency.CountryCode = "JPN";
             *
             * int rowsAffected = CurrencyManager.UpdateCurrency(updateCurrency);
             * Console.WriteLine("Update successful! {0} rows affected", rowsAffected);
             *
             #endregion
             */

            #region "UPDATE Colours TEST"
            Colour updateColours = new Colour();
            updateColours.Id   = 2;
            updateColours.Name = "Blue";

            //int colourRowsAffected = ColoursManager.UpdateColour(updateColours);
            //Console.WriteLine("Update successful! {0} rows affected", colourRowsAffected);

            #endregion

            #region "UPDATE Countries TEST"
            Country updateCountries = new Country();
            updateCountries.CountryCode = "GRE";
            updateCountries.Name        = "Greece Updated";

            //string countryRowsAffected = CountryManager.UpdateCountry(updateCountries);
            //Console.WriteLine("Update successful! {0} rows affected", countryRowsAffected);
            #endregion

            #region "UPDATE Types TEST"
            Type updateTypes = new Type();
            updateTypes.Id   = 2;
            updateTypes.Name = "Crypto";

            //int typeRowsAffected = TypesManager.UpdateType(updateTypes);
            //Console.WriteLine("Update successful! {0} rows affected", typeRowsAffected);

            #endregion
            #endregion

            #region "DELETE"

            #region "DELETE Currency TEST"
            Console.Write("\nPlease enter the Currency Id you wish to delete: ");
            string deleteCurrencyId = Console.ReadLine();
            CurrencyManager.DeleteCurrency(Int32.Parse(deleteCurrencyId));

            if (deleteCurrencyId != null)
            {
                Console.WriteLine(string.Format("\nCurrency Id {0} has been deleted.", deleteCurrencyId));
            }
            else
            {
                Console.WriteLine("Sorry, the currency ID cannot be deleted.");
            }
            #endregion

            #region "DELETE Colours TEST"
            Console.Write("\nPlease enter the Colour Id you wish to delete: ");
            string deleteColourId = Console.ReadLine();
            ColoursManager.DeleteColour(Int32.Parse(deleteColourId));

            if (deleteColourId != null)
            {
                Console.WriteLine(string.Format("\nColour Id {0} has been deleted.", deleteColourId));
            }
            else
            {
                Console.WriteLine("Sorry, the colour ID cannot be deleted.");
            }

            #endregion

            #region "DELETE Countries TEST"
            Console.Write("\nPlease enter the Country Code you wish to delete: ");
            string deleteCountryCode = Console.ReadLine();
            CountryManager.DeleteCountry(deleteCountryCode);

            if (deleteCountryCode != null)
            {
                Console.WriteLine("\nCountry Code {0} has been deleted.", deleteCountryCode);
            }
            else
            {
                Console.WriteLine("Sorry, the country code cannot be deleted.");
            }
            #endregion

            #region "DELETE Types TEST"
            Console.Write("\nPlease enter the Type Id you wish to delete: ");
            string deleteTypeId = Console.ReadLine();
            TypesManager.DeleteType(Int32.Parse(deleteTypeId));

            if (deleteTypeId != null)
            {
                Console.WriteLine(string.Format("\n Type Id {0} has been deleted.", deleteTypeId));
            }
            else
            {
                Console.WriteLine("Sorry, the type ID cannot be deleted.");
            }
            Console.WriteLine("");
            Console.WriteLine("Press any key to close...");
            Console.Read(); //keep console window open
            #endregion

            #endregion
        }