예제 #1
0
        /// <summary>
        /// Handle a request to register 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 registration successed and that a log
        /// entity in the database was created.
        /// </summary>
        /// <param name="person">The person to be registered.</param>
        /// <returns>A boolean value determining if the request failed or successed.</returns>
        /// <param name="clientName">The id of the client.</param>
        public bool RegisterVoteRequestHandler(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 = "register",
                    Client = clientName,
                    PollingTable = clientName,
                    Timestamp = (int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds
                };

                log.Save();

                return true;
            }

            return false;
        }
예제 #2
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());
        }