Exemplo n.º 1
0
        private void BtnRemove_Click(object sender, RoutedEventArgs e)
        {
            if (dgShow.SelectedItem != null)
            {
                PersonVM user = null;
                try
                {
                    user = (PersonVM)dgShow.SelectedItem;
                }
                catch (Exception)
                {
                    return;
                }

                Entities.Person dbUserRemove = _db.People.SingleOrDefault(u => u.Id == user.Id);

                if (dbUserRemove != null)
                {
                    _db.People.Remove(dbUserRemove);
                    _db.SaveChanges();

                    _people.Remove(user);
                }
            }
        }
Exemplo n.º 2
0
 private void RadioButton_Checked(object sender, RoutedEventArgs e)
 {
     if (dgShow.SelectedItem != null)
     {
         PersonVM user = null;
         try
         {
             user = (PersonVM)dgShow.SelectedItem;
         }
         catch (Exception)
         {
             return;
         }
         RadioButton button = (RadioButton)sender;
         if (button.IsChecked == true)
         {
             Entities.Person personForChange = _db.People.SingleOrDefault(p => p.Id == user.Id);
             if ((string)button.Content == "male")
             {
                 personForChange.Gender = "Male";
                 user.IsMale            = true;
                 user.IsFemale          = false;
             }
             else
             {
                 personForChange.Gender = "Female";
                 user.IsMale            = false;
                 user.IsFemale          = true;
             }
             _db.SaveChanges();
         }
     }
 }
Exemplo n.º 3
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            Entities.Person person = CreateRandPerson();

            _db.People.Add(person);
            _db.SaveChanges();

            _people.Add(new PersonVM
            {
                Id        = person.Id,
                Name      = person.Name,
                Surname   = person.Surname,
                Email     = person.Email,
                ImageUrl  = person.Photo,
                IsMale    = person.Gender == "Male" ? true : false,
                IsFemale  = person.Gender == "Female" ? true : false,
                Birthdate = person.Birthdate
            });
        }
Exemplo n.º 4
0
        private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            PersonVM user = null;

            try
            {
                user = (PersonVM)dgShow.SelectedItem;
            }
            catch (Exception)
            {
                return;
            }

            DatePicker datePicker = (DatePicker)sender;

            Entities.Person personForChange = _db.People.SingleOrDefault(p => p.Id == user.Id);
            personForChange.Birthdate = datePicker.SelectedDate.Value.Date;
            _db.SaveChanges();
        }
Exemplo n.º 5
0
        private void BtnChange_Click(object sender, RoutedEventArgs e)
        {
            if (dgShow.SelectedItem != null)
            {
                PersonVM user = null;
                try
                {
                    user = (PersonVM)dgShow.SelectedItem;
                }
                catch (Exception)
                {
                    return;
                }

                Entities.Person dbPersonEdit = _db.People.SingleOrDefault(u => u.Id == user.Id);
                Entities.Person newUser      = CreateRandPerson();

                if (dbPersonEdit != null)
                {
                    dbPersonEdit.Name      = newUser.Name;
                    dbPersonEdit.Surname   = newUser.Surname;
                    dbPersonEdit.Email     = newUser.Email;
                    dbPersonEdit.Photo     = newUser.Photo;
                    dbPersonEdit.Gender    = newUser.Gender;
                    dbPersonEdit.Birthdate = newUser.Birthdate;

                    _db.SaveChanges();

                    user.Id        = dbPersonEdit.Id;
                    user.Name      = dbPersonEdit.Name;
                    user.Surname   = dbPersonEdit.Surname;
                    user.Email     = dbPersonEdit.Email;
                    user.ImageUrl  = dbPersonEdit.Photo;
                    user.IsMale    = dbPersonEdit.Gender == "Male" ? true : false;
                    user.IsFemale  = !user.IsMale;
                    user.Birthdate = dbPersonEdit.Birthdate;
                }
            }
        }