コード例 #1
0
        public void Insert(string Name, string Language, int Population)
        {
            var added = db.Countries.Add(new Country
            {
                Name       = Name,
                Language   = Language,
                Population = Population
            });

            db.SaveChanges();
        }
コード例 #2
0
        public Town Insert(string Name, int Population, string Country)
        {
            var foundCountry = db.Countries.Where(x => x.Name == Country).Single();

            var added = db.Towns.Add(new Town
            {
                Name       = Name,
                Country    = foundCountry,
                Population = Population
            });

            db.SaveChanges();

            return(added);
        }
コード例 #3
0
        protected void ButtonAdd_Click(object sender, EventArgs e)
        {
            string countryName     = (string)ViewState["CountryName"];
            string countryLanguage = (string)ViewState["CountryLanguage"];

            if (string.IsNullOrWhiteSpace(countryName) || string.IsNullOrWhiteSpace(countryLanguage))
            {
                return;
            }

            SettlementsContext db = new SettlementsContext();

            var contId = (int)ViewState["CountryContinentId"];

            var foundContinent = db.Continents.Where(x => x.Id == contId).FirstOrDefault();

            var newCountry = new Country
            {
                Name       = countryName,
                Language   = countryLanguage,
                Population = (int)ViewState["CountryPopulation"],
                Continend  = foundContinent
            };

            db.Countries.Add(newCountry);
            db.SaveChanges();
        }