コード例 #1
0
        public virtual ActionResult Create( City newCity )
        {
            TempData[ "info" ] = string.Format(
                    "There's no database behind this page but I've received from you: {0} and {1}" ,
                    newCity.Name ,
                    this._countries.Where( c => c.Id == newCity.CountryId ).SingleOrDefault( ).Name
                );

            IDictionary<string , IEnumerable<SelectListItem>> countriesByContinent = new Dictionary<string , IEnumerable<SelectListItem>>( );

            foreach ( var continent in this._continents )
            {
                var countryList = new List<SelectListItem>( );

                foreach ( var country in this._countries.Where( c => c.ContinentId == continent.Id ) )
                {
                    countryList.Add( new SelectListItem { Value = country.Id.ToString( ) , Text = country.Name } );
                }

                countriesByContinent.Add( continent.Name , countryList );
            }

            ViewBag.CountriesList = countriesByContinent;

            return View( MVC.Select.Cities.Views.Create );
        }
コード例 #2
0
 public void InsertOrUpdate( City city )
 {
     if ( city.Id == default( int ) )
     {
         // New entity
         context.Cities.Add( city );
     }
     else
     {
         // Existing entity
         context.Entry( city ).State = EntityState.Modified;
     }
 }