private void Populate(ISession session)
        {
            Assert.IsNotNull(session);
            session.BeginTransaction();
            try
            {
                var person = new Person
                                 {
                                     FirstName = "brady",
                                     LastName = "gaster"
                                 };

                session.Save(person);
                Assert.Greater(person.Id, 0);

                int newPersonId = person.Id;

                person.FirstName = "Gina";
                session.Update(person);

                Assert.Greater(person.Id, 0);
                Assert.IsTrue(person.Id == newPersonId);
                session.Transaction.Commit();
            }
            catch
            {
                session.Transaction.Rollback();
            }
        }
Ejemplo n.º 2
0
        private Person[] GetAutoGeneratedPeople(int number)
        {
            List<Person> people = new List<Person>();

            for (int i = 0; i < number; i++)
            {
                string firstName = string.Format("Name{0}", i);
                string lastName = string.Format("Lastname{0}", i);
                string phone = GeneratePhoneNumber();

                Person singlePerson = new Person(firstName, lastName, phone);
                people.Add(singlePerson);
            }

            return people.ToArray();
        }
        public void sample_isessionfactorycreator_creates_session_factory_instances()
        {
            var sessionFactory = new PeopleSessionFactoryCreator().Create();
            Assert.IsNotNull(sessionFactory);

            using (var session = sessionFactory.OpenSession())
            {
                session.BeginTransaction();

                try
                {
                    Assert.IsNotNull(session);

                    var person = new Person
                    {
                        FirstName = "brady",
                        LastName = "gaster"
                    };

                    session.Save(person);
                    Assert.Greater(person.Id, 0);

                    int newPersonId = person.Id;

                    person.FirstName = "Gina";
                    session.Update(person);

                    Assert.Greater(person.Id, 0);
                    Assert.IsTrue(person.Id == newPersonId);

                    session.Transaction.Commit();
                }
                catch
                {
                    session.Transaction.Rollback();
                }
            }
        }
Ejemplo n.º 4
0
 public PersonViewModel(Person model, IValidationService validationService = null)
 {
     Model = model;
     _validationService = validationService;
     ConvertModelToViewModel(Model, this);
 }
Ejemplo n.º 5
0
 public static void ConvertViewModelToModel(PersonViewModel viewModel, Person model)
 {
     model.Firstname = viewModel.Firstname;
     model.Lastname = viewModel.Lastname;
     model.PhoneNumber = viewModel.PhoneNumber;
 }
Ejemplo n.º 6
0
 public static void ConvertModelToViewModel(Person model, PersonViewModel viewModel)
 {
     viewModel.Firstname = model.Firstname;
     viewModel.Lastname = model.Lastname;
     viewModel.PhoneNumber = model.PhoneNumber;
 }
        public void session_update_extension_method_updates_instances()
        {
            var person = new Person { FirstName = "brady", LastName = "gaster" };

            SessionFactory
                .For<Person>()
                    .OpenSession()
                        .Save<Person>(person, x =>
                            {
                                Assert.Greater(x.Id, 0);
                                x.FirstName = "Gina";
                            })
                        .Update<Person>(person, x =>
                            {
                                Assert.True(x.FirstName.Equals("Gina"));
                                Assert.True(x.Id == person.Id);
                            });
        }
        public void session_save_extension_method_saves_instances()
        {
            var person = new Person { FirstName = "brady", LastName = "gaster" };

            SessionFactory
                .For<Person>()
                    .OpenSession()
                        .Save<Person>(person);

            Assert.Greater(person.Id, 0);
        }
Ejemplo n.º 9
0
 private void AddPersonExecute()
 {
     var newPerson = new Person(string.Empty, string.Empty, string.Empty);
     _eventAggregator.GetEvent<PersonSelectionChangedEvent>().Publish(new Tuple<Person, bool>(newPerson, true));
 }
Ejemplo n.º 10
0
 private void PersonChanged(Person person)
 {
     PersonListItemViewModel existingPersonViewModel = People.SingleOrDefault(x => x.Model == person);
     if (existingPersonViewModel != null)
         PersonListItemViewModel.ConvertModelToViewModel(person, existingPersonViewModel);
     else
     {
         People.Add(new PersonListItemViewModel(person));
         _eventAggregator.GetEvent<UserActionHappenedEvent>().Publish("New person added");
     }
         
 }
 public static void ConvertModelToViewModel(Person model, PersonListItemViewModel viewModel)
 {
     viewModel.Lastname = model.Lastname;
 }
 public PersonListItemViewModel(Person personModel)
 {
     Model = personModel;
     Lastname = Model.Lastname;
 }
Ejemplo n.º 13
0
 public EditPersonViewModel(Person personModel, IValidationService validationService)
     : base(personModel, validationService)
 {
     ApplyEditCommand = new DelegateCommand(ApplyEditExecute, ApplyEditCanExecute);
     CancelEditCommand = new DelegateCommand(CancelEditExecute);
 }