Пример #1
0
        protected void SaveContinent_Click(object sender, EventArgs e)
        {
            int           currentContinentId = int.Parse(this.ContinentsListBox.SelectedValue);
            EarthEntities context            = new EarthEntities();
            var           currentContinent   = context.Continents.FirstOrDefault(c => c.Id == currentContinentId);

            currentContinent.Name = this.EditContinentName.Text;
            context.SaveChanges();

            this.EditContinentName.Text = "";
            this.ContinentsListBox.DataBind();
        }
Пример #2
0
        protected void DeleteContinent_Click(object sender, EventArgs e)
        {
            int selectedContinent = int.Parse(this.ContinentsListBox.SelectedValue);

            EarthEntities context = new EarthEntities();

            var continent = context.Continents.FirstOrDefault(c => c.Id == selectedContinent);

            context.Continents.Remove(continent);
            context.SaveChanges();

            this.ContinentsListBox.DataBind();
        }
Пример #3
0
        protected void AddContinent_Click(object sender, EventArgs e)
        {
            string newContinentName = this.NewContinent.Text.ToString();

            EarthEntities context = new EarthEntities();

            Continent newContinent = new Continent()
            {
                Name = newContinentName
            };

            context.Continents.Add(newContinent);
            context.SaveChanges();

            this.NewContinent.Text = "";
            this.ContinentsListBox.DataBind();
        }
Пример #4
0
        protected void Button2_Click1(object sender, EventArgs e)
        {
            int           selectedCountryId = (int)this.GridView1.SelectedDataKey.Value;
            EarthEntities context           = new EarthEntities();
            var           selectedCountry   = context.Countries.FirstOrDefault(c => c.Id == selectedCountryId);

            Town town = new Town()
            {
                Name       = this.NewTownName.Text,
                Population = int.Parse(this.NewTownPopulation.Text)
            };

            selectedCountry.Towns.Add(town);
            context.SaveChanges();

            this.NewTownName.Text       = "";
            this.NewTownPopulation.Text = "";

            this.GridView1.DataBind();
        }
Пример #5
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            var           selectedContinentId = int.Parse(this.ContinentsListBox.SelectedValue);
            EarthEntities context             = new EarthEntities();
            var           selectedContinent   = context.Continents.FirstOrDefault(c => c.Id == selectedContinentId);

            Country country = new Country()
            {
                Name       = this.NewCountryName.Text,
                Language   = this.NewCountryLanguage.Text,
                Population = int.Parse(this.NewCountryPopulation.Text)
            };

            selectedContinent.Countries.Add(country);
            context.SaveChanges();

            this.NewCountryPopulation.Text = "";
            this.NewCountryName.Text       = "";
            this.NewCountryLanguage.Text   = "";

            this.GridView1.DataBind();
        }