Beispiel #1
0
        public void EditContact()
        {
            try
            {
                ContactBookDBDModel db = new ContactBookDBDModel();

                if (SelectionManager.SelectedContact.ContactID <= 0)
                {
                    return;
                }
                var t = Task <Contacts> .Factory.StartNew(() =>
                {
                    return((from emp in db.Contacts
                            where emp.ContactID == SelectionManager.SelectedContact.ContactID
                            select emp).Single());
                });

                t.Wait();
                t.Result.HomePhone   = detailsView.homePhone;
                t.Result.WorkPhone   = detailsView.workPhone;
                t.Result.MobilePhone = detailsView.mobilePhone;

                t.Result.HomeAddress  = detailsView.homeAddress;
                t.Result.WorkAddress  = detailsView.workAddress;
                t.Result.OtherAddress = detailsView.otherAddress;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        public void AddContact()
        {
            ContactBookDBDModel db = new ContactBookDBDModel();

            Contacts contact = new Contacts();

            contact.FirstName    = v.newFirstName;
            contact.LastName     = v.newLastName;
            contact.HomePhone    = v.newHomePhone;
            contact.WorkPhone    = v.newWorkPhone;
            contact.MobilePhone  = v.newMobilePhone;
            contact.HomeAddress  = v.newHomeAddress;
            contact.WorkPhone    = v.newWorkAddress;
            contact.OtherAddress = v.newOtherAddress;
            db.Contacts.Add(contact);
            db.SaveChanges();
            v.UpdateListView();
        }
Beispiel #3
0
        public void DeleteContact()
        {
            try
            {
                ContactBookDBDModel db = new ContactBookDBDModel();

                Contacts contact = new Contacts();
                contact.ContactID = SelectionManager.SelectedContact.ContactID;
                var t = Task.Factory.StartNew(() => db.Contacts.Attach(contact));
                t.Wait();
                var t1 = Task.Factory.StartNew(() => db.Contacts.Remove(contact));
                t1.Wait();
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Något gick fel, kunde inte ta bort kontakten. " + ex.Message, "Felmeddelande");
            }
        }