Exemplo n.º 1
0
        public void Update(int id, tbl_contact contact)
        {
            // Cannot update invalid IDs
            if (id < 1)
            {
                return;
            }

            using (var context = new ContactContext())
            {
                var matches = context.tbl_contact.Where(c => c.ContactID == id);
                // Ignore invalid requests right now
                // Another option is to just create the contact
                // Another option is to figure out an error message
                // to display
                if (matches == null || matches.Count() < 1)
                {
                    return;
                }

                var elem = matches.First();
                elem.FirstName   = contact.FirstName;
                elem.LastName    = contact.LastName;
                elem.Address     = contact.Address;
                elem.PhoneNumber = contact.PhoneNumber;
                elem.Birthday    = contact.Birthday;
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
 public void Create(tbl_contact contact)
 {
     using (var context = new ContactContext())
     {
         context.tbl_contact.Add(contact);
         context.SaveChanges();
     }
 }