Example #1
0
        public ActionResult Index()
        {
            var voteProcess     = _voteProcessModelService.GetVoteProcessModels().ToList().Last();
            var voteProcessForm = new VoteProcessForm()
            {
                Id          = voteProcess.Id,
                CreatedAt   = voteProcess.CreatedAt,
                EndAt       = voteProcess.EndAt,
                ShowResults = voteProcess.ShowResults
            };

            ViewBag.CreatedAt   = voteProcess.CreatedAt;
            ViewBag.EndAt       = voteProcess.EndAt;
            ViewBag.showResults = voteProcess.ShowResults;
            return(View(voteProcessForm));
        }
Example #2
0
        public async Task <ActionResult> Index()
        {
            var voteProcess = (await _voteProcessModelService.GetVoteProcessModels().ToListAsync()).Last();

            ViewBag.ShowResults = voteProcess.ShowResults;
            ViewBag.EndAt       = voteProcess.EndAt;
            return(View());
        }
Example #3
0
        public async Task <ActionResult> Index(VoteForm voteForm)
        {
            if (_phoneNumberModelService.GetPhoneNumberModels().Where(phone => phone.PhoneNumber == voteForm.PhoneNumber).ToList().Count != 0)
            {
                ModelState.AddModelError("Телефонный номер", "Голос с использованием такого номера уже есть!");
            }
            if (voteForm.Place == null)
            {
                ModelState.AddModelError("Место для голосования", "Пожалуйста, выберите место для голосования.");
            }

            if (ModelState.IsValid)
            {
                TargetModel      target  = _targetModelService.GetTargetModel(Convert.ToInt32(voteForm.Target));
                VotePlaceModel   place   = _votePlaceModelService.GetVotePlaceModel(Convert.ToInt32(voteForm.Place));
                VoteProcessModel process = _voteProcessModelService.GetVoteProcessModels().ToList().Last();
                PhoneNumberModel phoneNumber;

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    ApplicationUser user = await _userManager.GetUserAsync(User);

                    phoneNumber = new PhoneNumberModel()
                    {
                        PhoneNumber = user.PhoneNumber
                    };
                }
                else
                {
                    phoneNumber = new PhoneNumberModel()
                    {
                        PhoneNumber = voteForm.PhoneNumber
                    };
                }

                _voteModelService.InsertVoteModel(
                    new VoteModel()
                {
                    CreatedAt     = DateTime.Now,
                    TargetId      = target,
                    VotePlaceId   = place,
                    PhoneNumberId = phoneNumber,
                    VoteProcessId = process
                });
                _logger.LogInformation($"{voteForm.PhoneNumber} voted");
                await _hubContext.Clients.All.SendAsync("Stat", "update");

                return(RedirectToAction(nameof(VoteSuccess)));
            }
            else
            {
                return(await Index());
            }
        }