/// <summary> /// Change the name of a group. Old and new name must be both different from the default group name. /// </summary> /// <param name="oldName"> The old name of the group</param> /// <param name="newName"> The new name of the group</param> /// <returns> True if the group name was changed successfully, false otherwise.</returns> public bool ModifyGroupName(string oldName, string newName) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(oldName) || String.IsNullOrEmpty(newName)) { return(false); } if (oldName == defGroup || newName == defGroup) { return(false); } if (oldName == newName) { return(true); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group tempGroup = sto.getGroupByUser(_userId, oldName); if (tempGroup == null) { return(false); } tempGroup.nameGroup = newName; return(sto.commit()); }
/// <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); }
/// <summary> /// Moved contacts, passed as parameter, from one group to another. /// </summary> /// <param name="groupIn"> The group name from which the contacts take.</param> /// <param name="groupOut"> The name of the group to move contacts.</param> /// <param name="contactList"> The list of contacts to be moved.</param> /// <returns> True if the contacts are moved successfully, false otherwise. In case of moving to the default group, contacts that are associated in more groups, will not move.</returns> public bool MoveContacts(string groupIn, string groupOut, List <Contact> contactList) { if (!_registered) { return(false); } if (String.IsNullOrEmpty(groupOut) || String.IsNullOrEmpty(groupIn) || contactList == null) { return(false); } if (groupIn == groupOut) { return(true); } Storage.StorageManager sto = new Storage.StorageManager(); Storage.Group tempGroupIn = sto.getGroupByUser(_userId, groupIn); Storage.Group tempGroupOut = sto.getGroupByUser(_userId, groupOut); if (tempGroupIn == null || tempGroupOut == null) { return(false); } List <Storage.Contact> stoContacts = ConvertToStorageContact(contactList); // se il groupOut e' other contacts, devo fare il controllo che gli elementi che vado a spostare // non stiano in altri gruppi if (groupOut.Equals(defGroup)) { List <Storage.Contact> orphan = sto.getContactsOrphanCandidates(_userId, groupIn); stoContacts = orphan.Intersect(stoContacts) as List <Storage.Contact>; } if (stoContacts == null) { //Nel caso che non sposto niente, cosa ritorno? return(true); } else { List <Storage.GroupContact> results = sto.moveContactsToGroup(stoContacts, tempGroupIn.groupID, tempGroupOut.groupID); if (results == null) { return(false); } } return(true); }
/// <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); }
/// <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)); } }
/// <summary> /// Начальное заполнение базы данных /// </summary> /// <param name="context"></param> protected override void Seed(MvpApp.Storage.Database db) { // Если нет ни одного студента if (db.Students.Count() == 0) { var g = new Storage.Group() { Number = 1 }; db.Groups.Add(g); var s = new Storage.Student() { Name = "Иван", FamilyName = "Иванов", Group = g }; db.Students.Add(s); db.SaveChanges(); } }
/// <summary> /// Remove contacts passed as parameter by the group with the name passed as parameter. /// </summary> /// <param name="name"> The name of the group from which to remove contacts.</param> /// <param name="contactList"> The list of contacts to be removed.</param> /// <returns> True if the contacts have been successfully removed, false otherwise.</returns> public bool RemoveContactsFromGroup(string name, List <Contact> contactList) { 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); } List <Storage.Contact> contacts = ConvertToStorageContact(contactList); return(sto.removeContactsFromGroup(contacts, tempGroup)); }
public Group Create(Storage.Group group) =>