Exemplo n.º 1
0
        public void TestAuditProperties()
        {
            AuditPerson p = new AuditPerson();

            p.Name        = "Frederik";
            p.DateOfBirth = new DateTime(1978, 12, 14);

            SessionManager.Instance.DefaultInterceptor = new AuditInterceptor();

            SessionManager.Instance.StartUnitOfWork();

            SessionManager.Instance.UnitOfWork.Save(p);

            Console.WriteLine(p.Name + " " + p.DateOfBirth + " " + p.Created + " " + p.Updated);

            SessionManager.Instance.UnitOfWork.Flush();

            SessionManager.Instance.CloseUnitOfWork();
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <AuditPerson> > GetPersonsAsync()
        {
            string             sqlProcedure = "PR_Audit_Persons_Read";
            List <AuditPerson> table        = new List <AuditPerson>();

            using (SqlConnection con = new SqlConnection(connectionString))
            {
                await con.OpenAsync();

                SqlCommand cmd = new SqlCommand(sqlProcedure, con)
                {
                    CommandType = CommandType.StoredProcedure
                };
                SqlDataReader reader = await cmd.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    while (await reader.ReadAsync())
                    {
                        Person person = new Person
                        {
                            Id        = reader.GetInt32("id"),
                            FirstName = reader.GetString("name"),
                            LastName  = reader.GetString("surname"),
                            Email     = reader.GetString("email"),
                            Phone     = reader.GetString("phone"),
                            IsActive  = !reader.GetBoolean("inactive")
                        };
                        AuditPerson audit = new AuditPerson
                        {
                            Person = person,
                            Type   = reader.GetString("crud_type"),
                            Time   = reader.GetDateTime("crud_time")
                        };
                        table.Add(audit);
                    }
                }
                await reader.CloseAsync();
            }
            return(table);
        }