Example #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Dni,Name,LastName,Email,IsActive")] Citizen citizen)
        {
            if (id != citizen.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (await _citizenServices.VerifyExistAsync(citizen.Dni))
                    {
                        ViewBag.Message = "Actualmente existe un ciudadano que contiene el mismo numero de identidad.";
                        return(View("Form", citizen));
                    }
                    await _citizenServices.UdateCitizenAsync(citizen);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CitizenExists(citizen.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View("Form", citizen));
        }