コード例 #1
0
        public void InsertNewPerson(Person person)
        {
            if (person.LastUpdated == DateTime.MinValue)
            {
                person.LastUpdated = DateTime.Now;
            }

            _database.Insert(person);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: KennyBu/PetaPocoUnitOfWork
        static void Main(string[] args)
        {
            var database = new Database("sqlserverce");
            var personRepo = new PersonRepository(database);
            var people = personRepo.GetAllPeople();

            DisplayPeople(people);

            Console.WriteLine("Type in a name:");
            var name = Console.ReadLine();
            Console.WriteLine("Type in an email:");
            var email = Console.ReadLine();

            var newPerson = new Person
                {
                    Name = name,
                    Email = email
                };

            try
            {
                personRepo.BeginTransaction();
                personRepo.InsertNewPerson(newPerson);
                personRepo.PromotePerson(newPerson);
                personRepo.Commit();
            }
            catch
            {
                personRepo.Rollback();
            }

            people = personRepo.GetAllPeople();

            DisplayPeople(people);

            Console.WriteLine("");
            Console.WriteLine("The person you entered should now be displayed.");
            Console.WriteLine("");
            Console.WriteLine("Press a key to enter another user and test the rollback.");
            Console.WriteLine("");
            Console.ReadLine();
            Console.WriteLine("");
            Console.WriteLine("Type in a name:");
            name = Console.ReadLine();
            Console.WriteLine("Type in an email:");
            email = Console.ReadLine();
            newPerson = new Person
            {
                Name = name,
                Email = email
            };

            personRepo.BeginTransaction();
            personRepo.InsertNewPerson(newPerson);
            personRepo.PromotePerson(newPerson);
            personRepo.Rollback();

            people = personRepo.GetAllPeople();

            DisplayPeople(people);
            Console.WriteLine("");
            Console.WriteLine("The person you entered should NOT be displayed.");
            Console.ReadLine();
        }
コード例 #3
0
 public void PromotePerson(Person person)
 {
     person.IsLeader = true;
     person.LastUpdated = DateTime.Now;
        _database.Update(person);
 }