Ejemplo n.º 1
0
        protected void GridViewCoutries_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var gridView = (GridView)sender;
            int countryId = int.Parse(gridView.DataKeys[e.RowIndex].Value.ToString());

            var data = new WorldData();

            var country = data.Countries.Find(countryId);
            data.Countries.Delete(country);

            data.SaveChanges();
            gridView.EditIndex = -1;
            this.BindCountries(null, null);
        }
Ejemplo n.º 2
0
        protected void ButtonInsert_OnClick(object o, EventArgs e)
        {
            var data = new WorldData();

            var name = this.GridViewCoutries.FooterRow.FindControl("TextBoxCountryName") as TextBox;
            var language = this.GridViewCoutries.FooterRow.FindControl("TextBoxCountryLanguage") as TextBox;
            var population = this.GridViewCoutries.FooterRow.FindControl("TextBoxCountryPopulation") as TextBox;

            var continentName = this.ListBoxContinents.SelectedValue;
            var continent = data.Continents.All().First(c => c.Name == continentName);

            var country = new Country
                              {
                                  Name = name.Text,
                                  Population = decimal.Parse(population.Text),
                                  Language = language.Text,
                              };
            continent.Countries.Add(country);
            data.Continents.Update(continent);
            data.SaveChanges();

            this.BindCountries(null, null);
        }
Ejemplo n.º 3
0
        protected void ListViewTowns_OnItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            var listView = (ListView)sender;
            int townId = int.Parse(listView.DataKeys[e.ItemIndex].Value.ToString());
            var data = new WorldData();
            var town = data.Towns.Find(townId);

            data.Towns.Delete(town);
            data.SaveChanges();

            listView.EditIndex = -1;
            this.BindTowns(null, null);
        }
Ejemplo n.º 4
0
        protected void ListViewTowns_OnItemInserting(object sender, ListViewInsertEventArgs e)
        {
            string name = e.Values["Name"].ToString();
            var population = decimal.Parse(e.Values["Population"].ToString());
            
            int countryId = int.Parse(this.GridViewCoutries.SelectedValue.ToString());

            var town = new Town
            {
                Name = name,
                Population = population,
                CountryId = countryId
            };

            var data = new WorldData();
            data.Towns.Add(town);

            data.SaveChanges();
            this.ListViewTowns.EditIndex = -1;
            this.BindTowns(null, null);
        }
Ejemplo n.º 5
0
        protected void ListViewTowns_OnItemUpdating(object sender, ListViewUpdateEventArgs e)
        {
            var listView = (ListView)sender;
            int townId = int.Parse(listView.DataKeys[e.ItemIndex].Value.ToString());
            var data = new WorldData();

            var editedRow = listView.Items[e.ItemIndex];
            var name = editedRow.FindControl("TextBoxTownName") as TextBox;
            var population = editedRow.FindControl("TextBoxTownPopulation") as TextBox;

            var town = data.Towns.Find(townId);
            town.Name = name.Text;
            town.Population = decimal.Parse(population.Text);

            data.Towns.Update(town);
            data.SaveChanges();

            listView.EditIndex = -1;
            this.BindTowns(null, null);
        }