Exemple #1
0
 public IActionResult UpdateCity(City city)
 {
     if (ModelState.IsValid)
     {
         cityDAO.UpdateCity(city);
         return(Ok());
     }
     else
     {
         return(new BadRequestObjectResult(ModelState));
     }
 }
 public IActionResult UpdateCity(City city)
 {
     // Should I compare id to City.id?
     if (ModelState.IsValid)
     {
         cityDAO.UpdateCity(city);
         return(Ok(city));
     }
     else
     {
         return(new BadRequestObjectResult(ModelState));
     }
 }
        /// <summary>
        /// Update the existing city information
        /// </summary>
        /// <param name="city"></param>
        /// <exception cref="CityManagerException">Thrown when unable to update city information</exception></exception>
        /// <returns>Returns the status of the update</returns>
        public bool UpdateCity(City city)
        {
            bool isUpdated = false;

            try
            {
                isUpdated = cityDAO.UpdateCity(city);
            }
            catch (CityDAOException ex)
            {
                throw new CityManagerException("Unable to update city information", ex);
            }


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

            cityDAO.UpdateCity(city);

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

            // TODO 00 (Controller): Redirect to the Update (GET) page, to re-display the city
            return(RedirectToAction("Update", new { id = city.CityId }));
        }
        // TODO: Protect City/Update with AuthorizeFilter so the user must be logged in (Admin)
        public IActionResult Update(City city)
        {
            // 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
            cityDAO.UpdateCity(city);

            // Store a message in TempData to be shown to the user
            TempData["message"]     = $"The city '{city.Name}' was updated.";
            TempData["HighlightId"] = city.CityId;

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

            return(RedirectToAction("Search", vm));
        }