コード例 #1
0
        /// <summary>
        /// Update a contact entity
        /// </summary>
        /// <param name="communicationType">The contact communication type</param>
        /// <param name="updatedText">The modified text for an entity with this communicationType</param>
        /// <param name="contacts">The original contact entities</param>
        /// <param name="patronUri">The URI of the patron entity that is associated with this contact</param>
        /// <returns>success, message</returns>
        private async Task <Tuple <bool, string> > updateContact(communicationType communicationType, string[] updatedText, List <contact> contacts, string patronUri)
        {
            contact contactMethod;
            Tuple <bool, object, string> ret = new Tuple <bool, object, string>(true, null, "");

            contactMethod = contacts.FirstOrDefault(s => s.communicationtype == communicationType);

            if (updatedText.Length == 0 || (updatedText.Length == 1 && updatedText[0].Length == 0))
            {
                // is there an existing contact entity to delete?
                if (contactMethod != null)
                {
                    ret = await lcfEntityRequestAsync(rootURI + "contacts/" + contactMethod.identifier, typeof(contact), entityOperation.DELETE);
                }
            }
            else
            {
                // do we need to add a new contact entity?
                if (contactMethod == null)
                {
                    contact c = new contact();
                    c.patronref = patronUri;
                    c.locator   = new string[1];

                    for (int i = 0; i < updatedText.Length; i++)
                    {
                        c.locator[i] = updatedText[i];
                    }

                    c.communicationtype = communicationType;
                    ret = await lcfEntityRequestAsync(rootURI + "contacts", typeof(contact), entityOperation.POST, c);
                }
                else
                {
                    // do we need to modify an existing contact entity?
                    bool updateRequired = updatedText.Length != contactMethod.locator.Length;

                    for (int i = 0; i < updatedText.Length && !updateRequired; i++)
                    {
                        if (updatedText[i].CompareTo(contactMethod.locator[i]) != 0)
                        {
                            updateRequired = true;
                        }
                    }

                    if (updateRequired)
                    {
                        contactMethod.locator = updatedText;
                        ret = await lcfEntityRequestAsync(rootURI + "contacts/" + contactMethod.identifier, typeof(contact), entityOperation.PUT, contactMethod);
                    }
                }
            }

            return(new Tuple <bool, string>(ret.Item1, ret.Item3));
        }
コード例 #2
0
 public CommunicationView(string personID, string personURI, communicationType type, communicationGeneralType gType)
 {
     Comm = new Communication(personID, personID, type, gType);
 }