Exemplo n.º 1
0
        /// <summary>
        /// Handle a request to unregister a person.
        ///
        /// The method takes a PersonState object sent from
        /// a client application, which contains information
        /// about the person who should be registered.
        ///
        /// If the person does not exists or if the person
        /// already voted, the method will return false.
        /// Otherwise the method will return true meaning
        /// that the unregistration successed and that a log
        /// entity in the database was created.
        /// </summary>
        /// <param name="person">The person to be unregistrated.</param>
        /// <param name="clientName">The id of the client.</param>
        /// <returns>A boolean value determining if the request failed or successed.</returns>
        public bool UnregisterVoteRequestHandler(string clientName, Person person)
        {
            Contract.Requires(person != null);
            Contract.Ensures(!Contract.OldValue(VoterIdToPersonRequestHandler("", person.VoterId).Exists) || !Contract.OldValue(VoterIdToPersonRequestHandler("", person.VoterId).Voted) ? Contract.Result <bool>() == false : Contract.Result <bool>() == true);

            var personEntity = new PersonEntity();

            personEntity.Load(new Hashtable {
                { "id", person.DbId }
            });

            if (personEntity.Exists() && personEntity.Voted)
            {
                var log = new LogEntity {
                    PersonDbId   = personEntity.DbId,
                    Action       = "unregister",
                    Client       = clientName,
                    PollingTable = clientName,
                    Timestamp    = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds
                };

                log.Save();

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set the person the fetched logs must belong to.
        /// </summary>
        /// <param name="personEntity">The person which logs we will fetch.</param>
        /// <returns>The instance of the log resource for chaining purposes.</returns>
        public LogResource SetPerson(PersonEntity personEntity)
        {
            Contract.Requires(personEntity != null);
            Contract.Requires(personEntity.Exists());

            this.QueryBuilder.AddCondition("`person_id` = '" + personEntity.DbId + "'");

            return(this);
        }
Exemplo n.º 3
0
        public void TestPersonCreationUpdatingAndDeletion()
        {
            var person = new PersonEntity();

            person.Firstname    = "Jan";
            person.Lastname     = "Aagaard Meier";
            person.Cpr          = "0123456789";
            person.VoterId      = 1337;
            person.PollingVenue = "ITU";
            person.PollingTable = "42";

            person.Save();

            person = new PersonEntity();
            person.Load(new Hashtable {
                { "polling_table", "42" }
            });

            Assert.That(person.Exists());
            Assert.That(person.Firstname == "Jan");
            Assert.That(person.Lastname == "Aagaard Meier");
            Assert.That(person.Cpr == "0123456789");
            Assert.That(person.VoterId == 1337);
            Assert.That(person.PollingVenue == "ITU");
            Assert.That(person.PollingTable == "42");

            person.Firstname = "Niels";
            person.VoterId   = 314;

            person.Save();

            person = new PersonEntity();
            person.Load(new Hashtable {
                { "polling_table", "42" }
            });

            Assert.That(person.Exists());
            Assert.That(person.Firstname == "Niels");
            Assert.That(person.Lastname == "Aagaard Meier");
            Assert.That(person.Cpr == "0123456789");
            Assert.That(person.VoterId == 314);
            Assert.That(person.PollingVenue == "ITU");
            Assert.That(person.PollingTable == "42");

            person.Delete();

            person = new PersonEntity();
            person.Load(new Hashtable {
                { "polling_table", "42" }
            });

            Assert.That(!person.Exists());
        }