예제 #1
0
        public async Task <IActionResult> Index(VotationLoginViewModel votationLoginViewModel)
        {
            if (ModelState.IsValid)
            {
                if (await _citizenService.VerifyExistAsync(votationLoginViewModel.DNI) == false)
                {
                    ViewBag.Message = "EL ciudadano no existe o esta inactivo.";
                    return(View(votationLoginViewModel));
                }

                if (await _electionService.VerifyElectionOpenAsync() == false)
                {
                    ViewBag.Message = "No hay ningun proceso electoral en estos momentos.";
                    return(View(votationLoginViewModel));
                }

                if (await _electionService.VerifyCitizenVoteAsync(votationLoginViewModel.DNI))
                {
                    ViewBag.Message = "Usted ya ejercion su derecho al voto.";
                    return(View(votationLoginViewModel));
                }

                Citizen citizen = await _citizenService.GetCitizenByConditionAsync(c => c.Dni == votationLoginViewModel.DNI).Result.FirstOrDefaultAsync();

                HttpContext.Session.SetInt32(Configuration.Citizen, citizen.Id);
                return(RedirectToAction("Votation"));
            }

            return(View(votationLoginViewModel));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("Id,Dni,Name,LastName,Email,IsActive")] Citizen citizen)
        {
            if (ModelState.IsValid)
            {
                if (await _citizenServices.VerifyExistAsync(citizen.Dni))
                {
                    ViewBag.Message = "Actualmente existe un ciudadano que contiene el mismo numero de identidad.";
                    return(View("Form", citizen));
                }
                var newCitizen = await _citizenServices.InsertCitizenAsync(citizen);

                if (newCitizen != null)
                {
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View("Form", citizen));
        }