public IActionResult Add(City city)
        {
            int newCityId = cityDAO.AddCity(city);

            //return Redirect($"/city/ConfirmAdd/{newCityId}");
            return(RedirectToAction("ConfirmAdd", new { id = newCityId }));
        }
        private void AddCity(string countrycode = "")
        {
            string name       = CLIHelper.GetString("Name of the city:");
            string code       = CLIHelper.GetString("Country code:");
            string district   = CLIHelper.GetString($"District {name} is in:");
            int    population = CLIHelper.GetInteger($"Population of {name}:");

            City city = new City
            {
                CountryCode = code,
                Name        = name,
                District    = district,
                Population  = population
            };

            if (String.IsNullOrEmpty(countrycode))
            {
                cityDAO.AddCity(city);
            }
            else
            {
                cityDAO.AddCityAsCapital(city, countrycode);
            }

            Console.WriteLine("City added.");
        }
Example #3
0
        private MenuOptionResult AddCity()
        {
            SetColor(ConsoleColor.Cyan);
            string name       = GetString("Name of the city: ");
            string district   = GetString($"District {name} is in: ");
            int    population = GetInteger($"Population of {name}: ");

            // Create a city object and set its properties
            City newCity = new City()
            {
                Name        = name,
                CountryCode = country.Code,
                District    = district,
                Population  = population
            };

            // Add the city (AddCity)
            int newCityId = cityDAO.AddCity(newCity);

            if (newCityId > 0)
            {
                Console.WriteLine($"City was added with id {newCityId}.");
            }
            else
            {
                Console.WriteLine("City was not added");
            }
            ResetColor();
            return(MenuOptionResult.WaitAfterMenuSelection);
        }
        public IActionResult AddCity(City city)
        {
            IActionResult result = null;

            // Are there errors
            if (!ModelState.IsValid)
            {
                // Return the new view again
                result = View("AddCity");
            }
            else
            {
                try
                {
                    // Step 6 - Save new city information to database
                    _cityDao.AddCity(city);

                    CityViewModel vm = new CityViewModel();
                    vm.CountryCode = city.CountryCode;
                    vm.District    = city.District;

                    SetTempData("CityData", vm);

                    // Step 7 - Redirect the browser to the world/confirmation action to prevent re-submition
                    result = RedirectToAction("Confirmation", "World" /*, new { CountryCode = city.CountryCode, District = city.District }*/);
                }
                catch (Exception)
                {
                    // If we failed to add the city to the DAO then return to the form page
                    result = View("AddCity");
                }
            }

            return(result);
        }
        public IActionResult Add(City city)
        {
            // I might put some validation here, but I am lazy

            // TODO 05: Check model state before updating. If there are errors, return the form to the user.
            if (!ModelState.IsValid)
            {
                return(View(city));
            }

            // Use the dao to add the city
            int newCityId = cityDAO.AddCity(city);

            // TODO 02a: Store a message in TempData to be shown to the user
            TempData["message"] = $"The city '{city.Name}' was added. The new city ID is {newCityId}.";

            // Redirect to a confirmation page
            //return RedirectToAction("AddConfirmation", new { id = newCityId });
            // TODO 01: Redirect from add to search, passing Country and District in
            CitySearchVM vm = new CitySearchVM()
            {
                CountryCode = city.CountryCode,
                District    = city.District
            };

            return(RedirectToAction("Search", vm));
        }
Example #6
0
        public IActionResult New(City city)
        {
            // Save the City
            cityDao.AddCity(city);

            // Redirect the user to City/Index Action
            return(RedirectToAction("index", "city"));
        }
Example #7
0
        public ActionResult AddCity(City city)
        {
            cityDAO.AddCity(city);
            // return RedirectToAction("Confirmation");

            //let's search for the city within it's country and district
            return(RedirectToAction("SearchResult", "Day1", new { CountryCode = city.CountryCode, District = city.District }));
        }
Example #8
0
        public IActionResult Add(City city)
        {
            // Use the DAO to add a city
            cityDAO.AddCity(city);

            // Redirect to the Confirmation page
            return(RedirectToAction("ConfirmAdd"));
        }
        [ValidateAntiForgeryToken] //11. Validate the forgery token to prevent a Cross-site request forgery (CSRF) attack
        public IActionResult AddCity(City city)
        {
            //9. Save the city into our DAL
            cityDao.AddCity(city);

            //4. Redirect user to the Confirmation Action
            //return RedirectToAction("Confirmation");

            //10. Redirect the user to the "Search Result page" showing cities in the district they used
            return(RedirectToAction("SearchResult", "Day1", new { CountryCode = city.CountryCode, District = city.District }));
        }
Example #10
0
        public IActionResult Add(City city)
        {
            // I might put some validation here, but I am lazy

            // Use the dao to add the city
            int newCityId = cityDAO.AddCity(city);

            // Redirect to a confirmation page
            var obj = new { id = newCityId };

            return(RedirectToAction("AddConfirmation", obj));
        }
Example #11
0
        public IActionResult New(City city)
        {
            if (!ModelState.IsValid)
            {
                return(View(city));
            }
            // Save the City
            cityDao.AddCity(city);

            // Redirect the user to City/Index Action
            return(RedirectToAction("index", "city"));
        }
        public ActionResult AddCity(City city)
        {
            bool result = cityDAO.AddCity(city);

            if (result)
            {
                return(Created("", city));
            }
            else
            {
                return(BadRequest());
            }
        }
        public IActionResult New(City city)
        {
            //check to see if there were errors on the model
            if (!ModelState.IsValid)
            {
                return(View(city));
            }

            // Save the City
            cityDao.AddCity(city);

            // Redirect the user to City/Index Action
            return(RedirectToAction("index", "city"));
        }
 public IActionResult AddCity([FromBody] City city)
 {
     if (ModelState.IsValid)
     {
         int newId = cityDAO.AddCity(city);
         city = cityDAO.GetCityById(newId);
         // TODO 09a (Controller): Return CreatedAtRoute to return 201
         return(CreatedAtRoute("GetCity", new { id = newId }, city));
     }
     else
     {
         return(new BadRequestObjectResult(ModelState));
     }
 }
        public IActionResult Add(City city)
        {
            // TODO 07: Check model state before updating. If there are errors, return the form to the user.


            int newCityId = cityDAO.AddCity(city);

            // TODO 02a: Add a confirmation message to the user and then re-direct to the search page
            // TODO 03: Change from ViewData to TempData (here and in Layout, and above).
            ViewData["Message"] = $"City '{city.Name}' was added with id {newCityId}";

            // TODO 02b: Redirect to the search page so the user can see the added city, instead of to the
            // Confirm page
            return(RedirectToAction("ConfirmAdd", new { id = newCityId }));
        }
Example #16
0
        /// <summary>
        /// Adds a city to the database
        /// </summary>
        /// <param name="city"></param>
        /// <exception cref="CityManagerException">Thrown when unable to add city</exception>
        /// <returns>Returns the status of insertion to be done</returns>
        public bool AddCity(City city)
        {
            bool isAdded = false;

            try
            {
                isAdded = cityDAO.AddCity(city);
            }
            catch (CityDAOException ex)
            {
                throw new CityManagerException("Unable to add the city", ex);
            }


            return(isAdded);
        }
Example #17
0
        public IActionResult AddCity(City city)
        {
            IActionResult result = null;

            try
            {
                _db.AddCity(city);
                result = RedirectToAction("Results", new { Name = city.Name });
            }
            catch (Exception)
            {
                result = RedirectToAction("Results", new { Name = city.Name, Error = "Failed" });
            }

            return(result);
        }
Example #18
0
        public IActionResult Add(City city)
        {
            // I might put some validation here, but I am lazy

            // TODO 05: Check model state before updating. If there are errors, return the form to the user.

            // Use the dao to add the city
            int newCityId = cityDAO.AddCity(city);

            // TODO 02a: Store a message in TempData to be shown to the user


            // Redirect to a confirmation page
            return(RedirectToAction("AddConfirmation", new { id = newCityId }));
            // TODO 01: Redirect from add to search, passing Country and District in
        }
Example #19
0
        public IActionResult New(City city)
        {
            // Are there errors
            if (!ModelState.IsValid)
            {
                // Return the new view again
                return(View(city));
            }
            else
            {
                // Save the City
                cityDao.AddCity(city);

                // Redirect the user to City/Index Action
                return(RedirectToAction("list", "city"));
            }
        }
Example #20
0
        public IActionResult AddCity(City city)
        {
            if (ModelState.IsValid)
            {
                int newId = cityDAO.AddCity(city);

                // Read the city back to return it

                city = cityDAO.GetCityById(newId);

                // Return 201 Created, with a resource location point to our GetCity route
                return(CreatedAtRoute("GetCity", new { id = newId }, city));
            }
            else
            {
                // Pass errors back to the client program
                return(new BadRequestObjectResult(ModelState));
            }
        }
Example #21
0
        private void AddCity()
        {
            string name       = CLIHelper.GetString("Name of the city:");
            string code       = CLIHelper.GetString("Country code:");
            string district   = CLIHelper.GetString($"District {name} is in:");
            int    population = CLIHelper.GetInteger($"Population of {name}:");

            City city = new City
            {
                CountryCode = code,
                Name        = name,
                District    = district,
                Population  = population
            };

            cityDAO.AddCity(city);

            Console.WriteLine("City added.");
        }
Example #22
0
        public IActionResult Add(City city)
        {
            // TODO 07: Check model state before updating. If there are errors, return the form to the user.
            if (!ModelState.IsValid)
            {
                TempData["message"] = "Please try again. You messed up.";
                return(View(city));
            }

            // Use the DAO to add a city
            int cityId = cityDAO.AddCity(city);

            // TODO 02b: Add a confirmation message to the user and then re-direct to the search page
            // Does it show up? Why not?

            // TODO 03: Change from ViewData to TempData (here and in Layout, and above).

            // TODO 02a: Redirect to the search page
            TempData["message"] = $"Your city called {city.Name} was added.  The Id was {cityId}.";
            return(RedirectToAction("ConfirmAdd"));
        }
        public IActionResult New(City city)
        {
            IActionResult result = null;

            // See if there are errors
            if (!ModelState.IsValid)
            {
                // Display the New View again
                // with the errors
                result = View();
            }
            else
            {
                // Save the City
                cityDao.AddCity(city);

                // Redirect the user to City/Index Action
                result = RedirectToAction("index", "city");
            }

            return(result);
        }
Example #24
0
        public IActionResult Add(City city)
        {
            // Check model state before updating. If there are errors, return the form to the user.
            if (!ModelState.IsValid)
            {
                return(View(city));
            }

            int newCityId = cityDAO.AddCity(city);

            // Add a confirmation message to the user and then re-direct to the search page
            TempData["Message"] = $"City '{city.Name}' was added with id {newCityId}";

            // Redirect to the search page
            CitySearchVM vm = new CitySearchVM()
            {
                CountryCode = city.CountryCode,
                District    = city.District
            };

            return(RedirectToAction("Search", vm));
        }
Example #25
0
        // TODO: Protect City/Add with AuthorizeFilter so the user must be logged in (Admin)
        public IActionResult Add(CityVM cityVM)
        {
            // Check model state before updating. If there are errors, return the form to the user.
            if (!ModelState.IsValid)
            {
                return(View(cityVM));
            }

            // Use the dao to add the city
            int newCityId = cityDAO.AddCity(cityVM.City);

            // Store a message in TempData to be shown to the user
            TempData["message"]     = $"The city '{cityVM.City.Name}' was added. The new city ID is {newCityId}.";
            TempData["HighlightId"] = newCityId;

            // Redirect from add to search, passing Country and District in
            CitySearchVM vm = new CitySearchVM(GetCurrentUser())
            {
                CountryCode = cityVM.City.CountryCode,
                District    = cityVM.City.District
            };

            return(RedirectToAction("Search", vm));
        }
        public IActionResult Add(City city)
        {
            int newCityId = cityDAO.AddCity(city);

            return RedirectToAction("ConfirmAdd");
        }
Example #27
0
 public IActionResult AddCity(City city)
 {
     cityDAO.AddCity(city);
     return RedirectToAction("SearchResults", "" +
                             "")
 }