예제 #1
0
        public void UpdateContact(Contact contact)
        {
            KAContext context = new KAContext();

            context.Update(contact);
            this.SaveChanges(context);
        }
예제 #2
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            KAContext context = new KAContext();

            if (FirstNameTextBox.Text == "")
            {
                ResponseLabel.Content = "Podaj imię";
                return;
            }

            contactFromDataGrid.FirstName   = FirstNameTextBox.Text;
            contactFromDataGrid.LastName    = LastNameTextBox.Text;
            contactFromDataGrid.Age         = AgeTextBox.Text != "" ? int.Parse(AgeTextBox.Text) : -1;
            contactFromDataGrid.Sex         = Helper.GetSexComboBoxSelectedItemText(SexComboBox);
            contactFromDataGrid.AreaCode    = AreaCodeTextBox.Text;
            contactFromDataGrid.City        = CityTextBox.Text;
            contactFromDataGrid.Street      = StreetTextBox.Text;
            contactFromDataGrid.HouseNumber = HouseNumberTextBox.Text;
            contactFromDataGrid.FlatNumber  = FlatNumberTextBox.Text;
            contactFromDataGrid.Phone       = PhoneTextBox.Text;
            contactFromDataGrid.Email       = EmailTextBox.Text;
            contactFromDataGrid.Comment     = CommentTextBox.Text;

            Contact contact = _mapper.Map <Contact>(contactFromDataGrid);

            context.Update(contact);
            _repo.SaveChanges(context);
            this.Close();
        }
예제 #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            KAContext context = new KAContext();

            context.Database.Migrate();
        }
예제 #4
0
        public void CreateContact(Contact contact)
        {
            KAContext context = new KAContext();

            if (contact == null)
            {
                throw new ArgumentException(nameof(contact));
            }

            context.Contact.Add(contact);
            SaveChanges(context);
        }
예제 #5
0
        public void DeleteContact(Contact contact)
        {
            KAContext context = new KAContext();

            if (contact == null)
            {
                throw new ArgumentException(nameof(contact));
            }

            contact.IsDeleted = true;
            context.Update(contact);
            SaveChanges(context);
        }
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            KAContext context = new KAContext();

            if (FirstNameTextBox.Text.Trim() == "")
            {
                ResponseLabel.Content = "Podaj imię";
                return;
            }

            Contact newContact = _mapper.Map <Contact>(new ContactCreateDTO()
            {
                FirstName   = FirstNameTextBox.Text,
                LastName    = LastNameTextBox.Text,
                Age         = AgeTextBox.Text != "" ? int.Parse(AgeTextBox.Text) : -1,
                Sex         = Helper.GetSexComboBoxSelectedItemText(SexComboBox),
                AreaCode    = AreaCodeTextBox.Text,
                City        = CityTextBox.Text,
                Street      = StreetTextBox.Text,
                HouseNumber = HouseNumberTextBox.Text,
                FlatNumber  = FlatNumberTextBox.Text,
                Phone       = PhoneTextBox.Text,
                Email       = EmailTextBox.Text,
                Comment     = CommentTextBox.Text
            });


            _repo.CreateContact(newContact);

            if (_repo.SaveChanges(context))
            {
                FirstNameTextBox.Text                                       =
                    LastNameTextBox.Text                                    =
                        AgeTextBox.Text                                     =
                            AreaCodeTextBox.Text                            =
                                CityTextBox.Text                            =
                                    StreetTextBox.Text                      =
                                        HouseNumberTextBox.Text             =
                                            FlatNumberTextBox.Text          =
                                                PhoneTextBox.Text           =
                                                    EmailTextBox.Text       =
                                                        CommentTextBox.Text = " ";
                SexComboBox.SelectedItem                                    = null;
                ResponseLabel.Content                                       = "Dodano!";
            }
        }
예제 #7
0
        public IEnumerable <Contact> GetAllDeletedContacts(string where)
        {
            KAContext context = new KAContext();

            where = where.ToLower();
            return(context.Contact.AsNoTracking().
                   Where(c => c.FirstName.ToLower().Contains(where) ||
                         c.LastName.ToLower().Contains(where) ||
                         c.Sex.ToLower().Contains(where) ||
                         c.City.ToLower().Contains(where) ||
                         c.Street.ToLower().Contains(where) ||
                         c.AreaCode.ToLower().Contains(where) ||
                         c.HouseNumber.ToLower().Contains(where) ||
                         c.FlatNumber.ToLower().Contains(where) ||
                         c.Comment.ToLower().Contains(where) ||
                         c.Phone.ToLower().Contains(where) ||
                         c.Email.ToLower().Contains(where)).
                   Where(c => c.IsDeleted == true).
                   ToList());
        }
예제 #8
0
        public Contact GetContactById(int id)
        {
            KAContext context = new KAContext();

            return(context.Contact.Find(id));
        }
예제 #9
0
 public bool SaveChanges(KAContext context)
 {
     return(context.SaveChanges() >= 0);
 }