Пример #1
0
        public async Task <IActionResult> Edit([FromForm] Country country)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Unexpected error occurred: Not all fields were valid.");

                return(View(country));
            }

            var result = await _service.Edit(country);

            if (result.Message == ActionMessages.Updated)
            {
                return(RedirectToAction(nameof(Details), new { message = $"{result.Country.Name} was successfully updated." }));
            }
            else if (result.Message == ActionMessages.NotFound)
            {
                ModelState.AddModelError(string.Empty, $"Unexpected error occurred: No country with ID {country.Id} was found.");

                return(NotFound(ModelState));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Unexpected error: The action failed.");

                return(BadRequest(ModelState));
            }
        }
 public ActionResult Edit([Bind(Include = "Id,Name,Code")] Country country)
 {
     if (ModelState.IsValid)
     {
         Repository.Edit(country);
         return(RedirectToAction("Index"));
     }
     return(View(country));
 }
        public async Task <IActionResult> Edit(Country country)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newCountry = await _service.Edit(country);

            if (newCountry == null)
            {
                return(BadRequest("Something went wrong when updating the city. Please try again."));
            }

            return(Ok(newCountry));
        }
Пример #4
0
        public async Task <IActionResult> Put([FromBody] Country country)
        {
            var result = await _countryRepo.Edit(country);

            return(Ok(result));
        }
Пример #5
0
 public Country EditCountry(Country country)
 {
     return(_countryRepository.Edit(country));
 }