示例#1
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());
            }
        }
示例#2
0
        public ActionResult TargetDetail(string id)
        {
            var target = _targetModelService.GetTargetModel(int.Parse(id));

            return(View(target));
        }