Ejemplo n.º 1
0
        //
        // GET: /Country/
        // Controller action receives the Continent id parameter
        public ActionResult Index(int id)
        {
            // instantiate the db
            WorldDataContext _dataContext = new WorldDataContext();

            // Linq query to select the countries with the same continent id of the parameter
            var listofCountries = from c in _dataContext.Countries where c.continentId == id select c;

            //Validation to check if any country was found in the DB, to avoid user type invalid Id in the URL
            if (listofCountries.Count() == 0)
                //Redirect to Home
                return  RedirectToAction("Index","Home");

            //create a list of countries to send to the view
            IEnumerable<CountryObj> listOfItems = listofCountries.Select(c => new CountryObj(c.countryId, c.countryName, c.continentId ));
            //add a obj to the list with a invalid Id to use like a default value for the drop down list
            CountryObj c1 = new CountryObj(-1, "Select a Country", -1);
            listOfItems = (new[] { c1 }).Concat(listOfItems);

            // Get the Continent name and keep in the viewbag
            var  continentsearch = from c in _dataContext.Continents where c.continentId == id select c.continentName;
            IEnumerable<string> continentName = continentsearch.Select(c => c);
            ViewBag.ContinentName = continentName.First();

            return View(listOfItems);
        }
Ejemplo n.º 2
0
 public string getCountryName(int id)
 {
     string cName = "";
     WorldDataContext _dataContext = new WorldDataContext();
     var countrysearch = from c in _dataContext.Countries where c.countryId == id select c.countryName;
     IEnumerable<string> countryName = countrysearch.Select(c => c);
     cName = countryName.First();
     return cName;
 }
Ejemplo n.º 3
0
        //
        // GET: /Comment/
        public ActionResult Index()
        {
            // instantiate the db
            WorldDataContext _dataContext = new WorldDataContext();

            // Linq query to get the comments list
            var listofComments = from c in _dataContext.Infos select c;

            IEnumerable<CommentObj> listOfItems = listofComments.Select(c => new CommentObj(c.infoId, c.name, c.countryId, c.dateOfVisit,c.countryInformation));

            return View(listOfItems);
        }
Ejemplo n.º 4
0
 public ActionResult Create(Info info)
 {
     //Get the HttpPost request from the Comments form and fill with the remaining information
     info.countryId = Convert.ToInt16(Session["CountryId"]);
     info.infoDate = DateTime.Now;
     info.ip = GetUserIP();
     info.ipLocation = getCityLocationFromIp(info.ip);
     WorldDataContext _dataContext = new WorldDataContext();
     //Insert the Info object into the database and submit the changes
     _dataContext.Infos.InsertOnSubmit(info);
     _dataContext.SubmitChanges();
     return Redirect("/");
 }