Ejemplo n.º 1
0
        protected void LinkButtonSaveQuestion_Click(object sender, EventArgs e)
        {
            try
            {
                int? continentId = Convert.ToInt32(Request.Params["continentId"]);

                if (continentId != null && continentId > 0)
                {
                    WorldInfoEntities context = new WorldInfoEntities();
                    Continent continent = context.Continents.Find(continentId);

                    if (continent != null)
                    {
                        continent.Name = this.TextBoxContinentName.Text;
                        context.SaveChanges();
                        Response.Redirect("~/ManageContinents.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                this.TextBoxErrorMessage.Visible = true;
                this.TextBoxErrorMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 2
0
        protected void LinkButtonSaveTown_Click(object sender, EventArgs e)
        {
            try
            {
                int? townId = Convert.ToInt32(Request.Params["townId"]);

                if (townId != null && townId > 0)
                {
                    WorldInfoEntities context = new WorldInfoEntities();
                    Town town = context.Towns.Find(townId);

                    if (town != null)
                    {
                        town.Name = this.TextBoxTownName.Text;
                        town.Population = long.Parse(this.TextBoxPopulation.Text);
                        town.CountryId = int.Parse(this.ListBoxCountries.SelectedValue);
                        context.SaveChanges();
                        Response.Redirect("~/ManageTowns.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                this.LiteralErrorMessage.Visible = true;
                this.LiteralErrorMessage.Text = ex.Message;
            }
        }
 protected void LinkButtonSaveQuestion_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         WorldInfoEntities context = new WorldInfoEntities();
         Continent continent = new Continent();
         continent.Name = this.TextBoxContinentName.Text;
         context.Continents.Add(continent);
         context.SaveChanges();
         Response.Redirect("~/ManageContinents.aspx");
     }
 }
Ejemplo n.º 4
0
 protected void LinkButtonDeleteTown_Command(object sender, CommandEventArgs e)
 {
     try
     {
         var id = int.Parse(e.CommandArgument.ToString());
         WorldInfoEntities context = new WorldInfoEntities();
         Town town = context.Towns.Find(id);
         context.Towns.Remove(town);
         context.SaveChanges();
         Response.Redirect("~/ManageTowns.aspx");
     }
     catch (Exception ex)
     {
         this.LiteralErrorMessage.Visible = true;
         this.LiteralErrorMessage.Text = ex.Message;
     }
 }
Ejemplo n.º 5
0
        protected void LinkButtonSaveCountry_Click(object sender, EventArgs e)
        {
            try
            {
                int? countryId = Convert.ToInt32(Request.Params["countryId"]);

                if (countryId != null && countryId > 0)
                {
                    WorldInfoEntities context = new WorldInfoEntities();
                    Country country = context.Countries.Find(countryId);

                    if (country != null)
                    {
                        country.Name = this.TextBoxCountryName.Text;
                        country.Population = long.Parse(this.TextBoxPopulation.Text);
                        country.Language = this.TextBoxLanguage.Text;
                        country.ContinentId = int.Parse(this.ListBoxContinents.SelectedValue);
                        if (this.FileUploadFlag.FileBytes.Length > 0)
                        {
                            country.Flag = this.FileUploadFlag.FileBytes;
                        }

                        if (this.CheckRemoveFlag.Checked)
                        {
                            country.Flag = null;
                        }

                        context.SaveChanges();
                        Response.Redirect("~/ManageCountries.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                this.LiteralErrorMessage.Visible = true;
                this.LiteralErrorMessage.Text = ex.Message;
            }
        }
Ejemplo n.º 6
0
 protected void LinkButtonSaveTown_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         WorldInfoEntities context = new WorldInfoEntities();
         Town town = new Town();
         town.Name = this.TextBoxTownName.Text;
         town.Population = long.Parse(this.TextBoxPopulation.Text);
         town.CountryId = int.Parse(this.ListBoxCountries.SelectedValue);
         context.Towns.Add(town);
         context.SaveChanges();
         Response.Redirect("~/ManageTowns.aspx");
     }
 }
 protected void LinkButtonSaveCountry_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         WorldInfoEntities context = new WorldInfoEntities();
         Country country = new Country();
         country.Name = this.TextBoxCountryName.Text;
         country.Population = long.Parse(this.TextBoxPopulation.Text);
         country.Language = this.TextBoxLanguage.Text;
         country.ContinentId = int.Parse(this.ListBoxContinents.SelectedValue);
         country.Flag = this.FileUploadFlag.FileBytes;
         context.Countries.Add(country);
         context.SaveChanges();
         Response.Redirect("~/ManageCountries.aspx");
     }
 }