示例#1
0
        /// <summary>
        /// Update a single contact based on Id.
        /// </summary>
        public Contact Update(int id, string firstName, string lastName,
                              string email, string homeNumber, string mobileNumber, string imageHash)
        {
            var contact = GetById(id);

            if (contact == null)
            {
                throw new KeyNotFoundException();
            }

            // Probably the neater option based on required logic, in reality using
            // EF or another ORM could handle this internally inside the Data Layer
            // rather than manually in the service.
            contact.FirstName    = firstName ?? contact.FirstName;
            contact.LastName     = lastName ?? contact.LastName;
            contact.Email        = email ?? contact.Email;
            contact.HomeNumber   = homeNumber ?? contact.HomeNumber;
            contact.MobileNumber = mobileNumber ?? contact.MobileNumber;
            contact.ImageHash    = imageHash ?? contact.ImageHash;

            _contactProvider.Update(contact);

            return(contact);
        }