示例#1
0
        /// <summary>
        /// Checks the credentials entered by the user and returns true or
        /// false based on whether or not those credentials match what's in
        /// the database.
        /// <para>
        /// This method will also hydrate the <c>VoterId</c> field of the
        /// passed-in <c>UserCredentialsModel</c> if the Voter was found.
        /// </para>
        /// </summary>
        /// <param name="userCredentials">
        /// An instance of the <see cref="UserCredentialsModel"/> with its
        /// </param>
        /// <returns></returns>
        public bool ValidateUserCredentials(UserCredentialsModel userCredentials)
        {
            var foundVoter = _votersRepo.Get(
                vtf => vtf.LoginId == userCredentials.UsernameOrId &&
                vtf.LoginPin == userCredentials.PasswordOrPin &&
                vtf.ElectionId == userCredentials.ElectionId);

            // TODO: LOG THIS Login Attempt!  (Doesn't that break SRP?)

            if (foundVoter == null)
            {
                return(false);
            }

            userCredentials.VoterId = foundVoter.Id;

            return(true);
        }
        public async Task Handle(VoterCreated notification, CancellationToken cancellationToken)
        {
            var votersCount = await _votersRepository.GetCount();

            if (votersCount == 1)
            {
                var voter = await _votersRepository.Get(notification.VoterId);

                if (voter is null)
                {
                    throw new NullReferenceException(
                              $"cannot get voter in {nameof(GiveAdminRightsOnFirstVoterCreated)}");
                }

                using (_domainEvents.CollectPropertiesChange(voter))
                {
                    voter.IsAdministrator = true;
                }

                await _domainEvents.PublishCollected(cancellationToken);
            }
        }
示例#3
0
        public override async Task <Response <Empty> > Handle(VoteFor request, CancellationToken cancellationToken)
        {
            var identity = _identityService.GetIdentity();

            var voter = await _votersRepository.Get(identity.Id);

            if (voter is null)
            {
                throw new NullReferenceException(
                          "cannot find voter with specified id");
            }

            var vote = voter.Vote(
                voter.Id,
                request.QuestionId,
                request.AnswerId);

            await _domainEvents
            .CollectFrom(vote)
            .CollectFrom(voter)
            .PublishCollected(cancellationToken);

            return(Success());
        }