コード例 #1
0
 private void UpdateTagsChildCollection(Contact contact, Contact contactFromDb)
 {
     var tagsToDelete = (from tag in contactFromDb.Tags
                         let item = contact.Tags.SingleOrDefault(i => i.Id == tag.Id)
                         where item == null
                         select tag).ToList();
     if (tagsToDelete.Any())
     {
         foreach (var tag in tagsToDelete)
         {
             db.Entry(tag).State = EntityState.Deleted;
         }
     }
     foreach (var tag in contact.Tags)
     {
         if (tag.Id > 0)
         {
             var tagInDb = contactFromDb.Tags.Single(e => e.Id == tag.Id);
             db.Entry(tagInDb).CurrentValues.SetValues(tag);
             db.Entry(tagInDb).State = EntityState.Modified;
         }
         else
         {
             tag.ContactId = contact.Id;
             db.Tags.Add(tag);
         }
     }
 }
コード例 #2
0
ファイル: ContactRepository.cs プロジェクト: rayshen/WPF
 public void Save(Contact contact)
 {
     if (contact.Id == Guid.Empty)
         contact.Id = Guid.NewGuid();
     if (!_contactStore.Contains(contact))
         _contactStore.Add(contact);
     Serialize();
 }
コード例 #3
0
        public void UpdateContact(Contact contact)
        {

            var contactFromDb = db.Contacts.Where(x => x.Id == contact.Id).Include("Emails").Include("Tags").Include("Telephones").FirstOrDefault();

            contactFromDb.Address = contact.Address;
            contactFromDb.Name = contact.Name;
            contactFromDb.Surname = contact.Surname;
            UpdateEmailChildCollection(contact, contactFromDb);
            UpdateTelephonesChildCollection(contact, contactFromDb);
            UpdateTagsChildCollection(contact, contactFromDb);

            contactFromDb.DateUpdated = contact.DateUpdated;
            ///   contactFromDb.Tags = contact.Tags;

            db.SaveChanges();
        }
コード例 #4
0
        public void Add(Contact contact)
        {
            List<Contact> items = GetAll();
            int max = items.Count == 0 ? 0 : items.Max(i => i.Id);

            int newId = ++max;

            var xElement = _xmlDoc.Element("Contacts");
            if (xElement != null)
                xElement.Add(
                    new XElement("Contact", new XElement("Id", newId.ToString(CultureInfo.InvariantCulture)),
            new XElement("MembershipDate", contact.MembershipDate),
                             new XElement("FirstName", contact.FirstName),
                              new XElement("LastName", contact.LastName),
                              new XElement("EmailAddress", contact.EmailAddress),
                              new XElement("Phone", contact.Phone),
                              new XElement("Address1",
                                            new XElement("Street1", contact.Address1.Street1),
                                            new XElement("Street2", contact.Address1.Street2),
                                            new XElement("City", contact.Address1.City),
                                            new XElement("State", contact.Address1.State),
                                            new XElement("Zip", contact.Address1.Zip)
                                            ),
                            new XElement("DOB", contact.DOB),
                            new XElement("BusinessPhone", contact.BusinessPhone),
                            new XElement("Fax", contact.Fax),
                            new XElement("AHAMemberNumber", contact.AHAMemberNumber),
                            new XElement("EntryAdded", DateTime.UtcNow),
                            new XElement("EntryUpdated", DateTime.UtcNow),
                            new XElement("IsActive", contact.IsActive)

                            

                        ));


            _xmlDoc.Save(EntryFileFullName);
        }
コード例 #5
0
 public void AddContact(Contact contactToAdd)
 {
     db.Contacts.Add(contactToAdd);
     db.SaveChanges();
 }
コード例 #6
0
 private void UpdateEmailChildCollection(Contact contact, Contact contactFromDb)
 {
     var emailsToDelete = (from email in contactFromDb.Emails
                           let item = contact.Emails.SingleOrDefault(i => i.Id == email.Id)
                           where item == null
                           select email).ToList();
     if (emailsToDelete.Any())
     {
         foreach (var email in emailsToDelete)
         {
             db.Entry(email).State = EntityState.Deleted;
         }
     }
     foreach (var email in contact.Emails)
     {
         if (email.Id > 0)
         {
             var emailInDb = contactFromDb.Emails.Single(e => e.Id == email.Id);
             db.Entry(emailInDb).CurrentValues.SetValues(email);
             db.Entry(emailInDb).State = EntityState.Modified;
         }
         else
         {
             email.ContactId = contact.Id;
             db.Emails.Add(email);
         }
     }
 }
コード例 #7
0
 public void UpdateContact(Contact contact)
 {
     contact.DateUpdated = DateTime.Now;
     _contactRepository.UpdateContact(contact);
 }
コード例 #8
0
 public void AddContact(Contact contactToAdd)
 {
     contactToAdd.DateUpdated = DateTime.Now;
     _contactRepository.AddContact(contactToAdd);
 }
コード例 #9
0
 public void Delete(Contact contact)
 {
     this.contactStore.Remove(contact);
     Serialize();
 }
コード例 #10
0
ファイル: Main.cs プロジェクト: chudson121/ContactManager
        private Contact LoadContactFromInput()
        {
            Contact c = new Contact();
            c.FirstName = txtFirstName.Text;
            c.LastName = txtLastName.Text;
            c.EmailAddress = txtEmail.Text;
            c.Phone = txtPhone.Text;
            c.Address1 = new Address(txtStreet.Text, string.Empty, txtCity.Text, cmbState.Text, txtZip.Text);
            c.MembershipDate = Convert.ToDateTime(dtpMembership.Text);
            c.DOB = Convert.ToDateTime(dtpDOB.Text);
            c.BusinessPhone = txtBusPhone.Text;
            c.Fax = txtFax.Text;
            c.AHAMemberNumber = txtAHANum.Text;
            c.IsActive = chkActive.Checked;
            return c;

        }
コード例 #11
0
ファイル: Contacts.cs プロジェクト: chudson121/ContactManager
 public void Add(Contact newContact)
 {
     conArray.Add(newContact);
 }
コード例 #12
0
 public void Delete(Contact contact)
 {
     _xmlDoc.Root.Elements().Where(e => e.Attribute("Id").Value.Equals(contact.Id.ToString())).Select(e => e).Single().Remove();
     _xmlDoc.Save(EntryFileFullName);
 }
コード例 #13
0
        public void UpdateEntry(Contact contact)
        {
            string nodeName = "Contact";
            //find original
            var xmlElement = (from item in _xmlDoc.Descendants(nodeName)
                              let xElement = item.Element("Id")
                              where xElement != null && xElement.Value == contact.Id.ToString()
                              select item).Single();
            var oldContact = new Contact(xmlElement);

            xmlElement.ReplaceWith(
                  new XElement("Contact", new XElement("Id", contact.Id),
          new XElement("MembershipDate", contact.MembershipDate),
                           new XElement("FirstName", contact.FirstName),
                            new XElement("LastName", contact.LastName),
                            new XElement("EmailAddress", contact.EmailAddress),
                            new XElement("Phone", contact.Phone),
                            new XElement("Address1",
                                          new XElement("Street1", contact.Address1.Street1),
                                          new XElement("Street2", contact.Address1.Street2),
                                          new XElement("City", contact.Address1.City),
                                          new XElement("State", contact.Address1.State),
                                          new XElement("Zip", contact.Address1.Zip)
                                          ),
                          new XElement("DOB", contact.DOB),
                          new XElement("BusinessPhone", contact.BusinessPhone),
                          new XElement("Fax", contact.Fax),
                          new XElement("AHAMemberNumber", contact.AHAMemberNumber),
                          new XElement("EntryAdded", contact.EntryAdded),
                          new XElement("EntryUpdated", DateTime.UtcNow),
                        new XElement("IsActive", contact.IsActive)

                      ));

            //update with this one.
            _xmlDoc.Save(EntryFileFullName);
        }