public void InsertNewPerson(Person person) { if (person.LastUpdated == DateTime.MinValue) { person.LastUpdated = DateTime.Now; } _database.Insert(person); }
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(); }
public void PromotePerson(Person person) { person.IsLeader = true; person.LastUpdated = DateTime.Now; _database.Update(person); }