示例#1
0
 public long Insert(Contact contact)
 {
     try
     {
         _contactsContext.Contacts.Add(contact);
         _contactsContext.SaveChanges();
     }
     catch (Exception)
     {
         throw new Exception($"Entity {contact.FirstName} {contact.LastName} not inserted in database!");
     }
     return contact.Id;
 }
示例#2
0
        public void Update(int id, Contact contact)
        {
            var contactToUpdate = GetContactById(id);
            if (contactToUpdate == null)
            {
                throw new Exception("Contact does not exist in database");
            }

            try
            {
                contactToUpdate.Address = contact.Address;
                contactToUpdate.BirthDate = contact.BirthDate;
                contactToUpdate.City = contact.City;
                contactToUpdate.Email = contact.Email;
                contactToUpdate.FirstName = contact.FirstName;
                contactToUpdate.LastName = contact.LastName;
                contactToUpdate.Telephone = contact.Telephone;
                contactToUpdate.ZipCode = contact.ZipCode;

                _contactsContext.Update(contactToUpdate);
                _contactsContext.SaveChanges();
            }
            catch (Exception e) { throw e; }

        }