Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void TestPersonAndLogInteractivity()
        {
            var person = new PersonEntity();

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

            Assert.That(true);

            var logsBefore          = person.GetLogs();
            var mostRecentLogBefore = person.GetMostRecentLog();

            Assert.That(logsBefore.Count == 0);
            Assert.That(mostRecentLogBefore == null);

            var logA = new LogEntity {
                PersonDbId   = person.DbId,
                Action       = "register",
                Client       = "someotherclient 8",
                PollingTable = "8",
                Timestamp    = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds
            };

            logA.Save();

            Assert.That(logA.Exists());

            var logB = new LogEntity {
                PersonDbId   = person.DbId,
                Action       = "unregister",
                Client       = "someotherclient 8",
                PollingTable = "8",
                Timestamp    = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds + 1
            };

            logB.Save();

            Assert.That(logB.Exists());

            var logsAfter          = person.GetLogs();
            var mostRecentLogAfter = person.GetMostRecentLog();

            Assert.That(logsAfter.Count == 2);

            Assert.That(mostRecentLogAfter != null);
            Assert.That(mostRecentLogAfter.Exists());
            Assert.That(mostRecentLogAfter.Action == "unregister");

            logA.Delete();
            logB.Delete();

            Assert.That(!logA.Exists());
            Assert.That(!logB.Exists());
        }
Ejemplo n.º 3
0
        public void TestLogCreationUpdatingAndDeletion()
        {
            var log = new LogEntity {
                PersonDbId   = 1,
                Action       = "register",
                Client       = "someclient 8",
                PollingTable = "8",
                Timestamp    = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds
            };

            log.Save();

            log = new LogEntity();
            log.Load(new Hashtable {
                { "client", "someclient 8" }
            });

            Assert.That(log.Exists());
            Assert.That(log.PersonDbId == 1);
            Assert.That(log.Action == "register");
            Assert.That(log.Client == "someclient 8");
            Assert.That(log.PollingTable == "8");
            Assert.That(log.Timestamp > 0);

            log.Action       = "unregister";
            log.PollingTable = "5";

            log.Save();

            log = new LogEntity();
            log.Load(new Hashtable {
                { "client", "someclient 8" }
            });

            Assert.That(log.Exists());
            Assert.That(log.PersonDbId == 1);
            Assert.That(log.Action == "unregister");
            Assert.That(log.Client == "someclient 8");
            Assert.That(log.PollingTable == "5");
            Assert.That(log.Timestamp > 0);

            log.Delete();

            log = new LogEntity();
            log.Load(new Hashtable {
                { "client", "someclient 8" }
            });

            Assert.That(!log.Exists());
        }
Ejemplo n.º 4
0
        public static LogEntity WriteLog(LogTypeEnum logType, string operateModule, string logContent)
        {
            string    msg = string.Empty;
            LogEntity log = new LogEntity
            {
                Type          = logType,
                Operator      = HttpContext.Current.User.Identity.Name,
                OperateModule = operateModule,
                OperateTime   = DateTime.Now,
                Msg           = logContent
            };

            log.Save(out msg);

            return(log);
        }