Пример #1
0
        // The business logic behind the UI should provide the contacts data.
        // If WPF is used for example, the view model should prepare a Contact object and pass it to this service.
        public bool AddContact(Contact contact)
        {
            if (contact == null)
                return false;

            try
            {
                this.contactsContainer.ContactSet.Add(contact);
                var writtenObjectsCount = this.contactsContainer.SaveChanges();
                return writtenObjectsCount > 0;
            }
            catch
            {
                // TODO: log exception
                return false;
            }
        }
Пример #2
0
        public bool UpdateContact(int contactId, Contact updateData)
        {
            var contactToUpdate = this.contactsContainer.ContactSet.Find(contactId);

            if (contactToUpdate == null || updateData == null || contactToUpdate.Equals(updateData))
                return false;
            try
            {
                // TODO: Update contact's details from updateData object

                var writtenObjectsCount = this.contactsContainer.SaveChanges();
                return writtenObjectsCount > 0;
            }
            catch
            {
                // TODO: log exception
                return false;
            }
        }