示例#1
0
        /// <summary>
        /// Added the contacts passed as parameter to the group that has the name as parameter passed.
        /// QUANDO SI INVOCA STO METODO IL GRUPPO DEVE ESSERE CREATO.
        /// </summary>
        /// <param name="name"> The group name to add contacts</param>
        /// <param name="contactList"> The list of contacts to be added.</param>
        /// <returns> True if the contacts have been added successfully, false otherwise.</returns>
        public bool AddContactsInGroup(string name, List <Contact> contactList, int servID)
        {
            if (!_registered)
            {
                return(false);
            }
            if (String.IsNullOrEmpty(name) || contactList == null)
            {
                return(false);
            }

            Storage.StorageManager sto       = new Storage.StorageManager();
            Storage.Group          tempGroup = sto.getGroupByUser(_userId, name);
            if (tempGroup == null)
            {
                return(false);
            }

            Dictionary <string, string> contactsToAdd = new Dictionary <string, string>();

            foreach (Security.Contact con in contactList)
            {
                if (con == null || contactsToAdd.ContainsKey(con.Email))
                {
                    continue;
                }
                contactsToAdd.Add(con.Email, con.Name);
            }

            // Insert contacts into the database
            List <Storage.Contact> contactsAdded = sto.addContacts(contactsToAdd, servID);

            List <Storage.Contact> contactsToRemove = new List <Storage.Contact>();

            foreach (Storage.Contact c in sto.getContactsByGroup(_userId, defGroup))
            {
                if (c == null)
                {
                    continue;
                }
                if (contactsAdded.Contains(c))
                {
                    contactsToRemove.Add(c);
                }
            }
            Storage.Group otherGroup = sto.getGroupByUser(_userId, defGroup);
            sto.removeContactsFromGroup(contactsToRemove, otherGroup);

            // Link the contacts to the group
            List <Storage.GroupContact> result = sto.addContactsToGroup(contactsAdded, tempGroup);

            if (result == null)
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// Creates a new group with the name passed to the parameter if the group does not exist
        /// and adds the contacts passed to the parameter.
        /// </summary>
        /// <param name="name">The group name to create.</param>
        /// <param name="contactList"> The list of contacts to be added to the group.</param>
        /// <returns> True if the group was successfully created and contacts have been added, false otherwise.</returns>
        public bool CreateGroup(string name, List <Contact> contactList)
        {
            if (!_registered)
            {
                return(false);
            }
            if (String.IsNullOrEmpty(name) || contactList == null)
            {
                return(false);
            }

            if (name == defGroup)
            {
                return(false);
            }
            Storage.StorageManager sto        = new Storage.StorageManager();
            List <string>          groupNames = new List <string>();

            groupNames.Add(name);
            List <Storage.Group> groups = sto.addGroups(groupNames, _userId);

            if (groups == null || groups.Count == 0)
            {
                return(false);
            }

            List <Storage.Contact> contacts = ConvertToStorageContact(contactList);

            Storage.Group defStoGroup = null;
            foreach (Storage.Group g in sto.getGroupsByUserID(_userId))
            {
                if (g.nameGroup.Equals(defGroup))
                {
                    defStoGroup = g;
                    break;
                }
            }
            List <Storage.GroupContact> result2 = sto.addContactsToGroup(contacts, groups[0]);

            if (result2 == null)
            {
                return(false);
            }

            sto.removeContactsFromGroup(contacts, defStoGroup);

            return(true);
        }
示例#3
0
        /// <summary>
        /// Removes the group with the name passed as parameter if it does exist.
        /// </summary>
        /// <param name="name">The name of the group.</param>
        /// <returns>True if the removal was successful, false otherwise.</returns>
        public bool RemoveGroup(string name, bool removeContacts)
        {
            if (!_registered)
            {
                return(false);
            }
            if (String.IsNullOrEmpty(name))
            {
                return(false);
            }

            if (name == defGroup)
            {
                return(false);
            }
            Storage.StorageManager sto  = new Storage.StorageManager();
            Storage.Group          temp = sto.getGroupByUser(_userId, name);
            if (temp == null)
            {
                return(false);
            }

            bool result;

            if (!removeContacts)
            {
                List <Storage.Contact> contacts = sto.getContactsByGroup(_userId, name);
                List <Storage.Contact> orphans  = sto.getContactsOrphanCandidates(_userId, name);
                result = sto.removeEntity <Storage.Group>(temp.groupID);
                if (sto.addContactsToGroup(orphans, sto.getGroupByUser(_userId, defGroup)) != null)
                {
                    return(result);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(sto.removeEntity <Storage.Group>(temp.groupID));
            }
        }