/// <summary> /// Button for importing contacts. /// </summary> private void BtnImportContacts_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Csv files (*.csv)|*.csv|All files (*.*)|*.*" }; if (openFileDialog.ShowDialog() == true) { ContactImporter.ImportFile(openFileDialog.FileName); } }
public static async Task <bool> ImportAsync(string tenant, HttpPostedFileBase file, LoginView meta) { string extension = Path.GetExtension(file.FileName); if (extension != ".vcf") { throw new VCardImportException("The uploaded file is not a valid vCard file."); } var vcards = Parse(file); var contacts = (from vcard in vcards where vcard != null select vcard.ToContact(tenant)).ToList(); return(await ContactImporter.ImportAsync(tenant, meta.UserId, contacts).ConfigureAwait(false)); }
public void CorrectEmptyItems() { ContactDTO contact = new ContactDTO { Name = "", Surname = "Novak", Address = "", BirthNumber = 7054251237, PhoneNumbers = new int?[] { 123456789, 987654321, 987456321 } }; string[] items = new string[] { "", "Novak", "7054251237", "", "123456789", "987654321", "987456321" }; Assert.AreSame(contact.ToString(), ContactImporter.ParseLineToContactDTO(items, 4).ToString()); }
public void CorrectAllItems() { ContactDTO contact = new ContactDTO { Name = "Jan", Surname = "Novak", Address = "a b 5", BirthNumber = 7054251237, PhoneNumbers = new int?[] { 123456789, null, null } }; string[] items = new string[] { "Jan", "Novak", "7054251237", "a b 5", "123456789" }; Assert.AreSame(contact.ToString(), ContactImporter.ParseLineToContactDTO(items, 4).ToString()); }
public void NotCorrectCharInPhone() { string[] items = new string[] { "", "Novak", "7054251237", "", "123456789", "987ghu21", "98x99v321" }; Assert.IsNull(ContactImporter.ParseLineToContactDTO(items, 4)); }
public void NotCorrectCharInBirthNumber() { string[] items = new string[] { "", "Novak", "7054f51237", "", "123456789", "987654321", "987456321" }; Assert.IsNull(ContactImporter.ParseLineToContactDTO(items, 4)); }
protected void btnWebMailLogin_Click(object sender, System.EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(ImportEmails)); member = (Member)Session["Member"]; if (member == null) { Response.Redirect("/signup"); } if (this.txtUserID.Text == "" || this.txtPassword.Text == "") { return; } Regex isNumeric = new Regex(@"^\d+$"); //strip email address string Login = txtUserID.Text; int AtSignIndex = Login.IndexOf("@"); if (AtSignIndex > 0) { if (emailCat.SelectedValue.ToLower() != "linkedin.com") { Login = Login.Substring(0, AtSignIndex); } } DateTime start = DateTime.Now; contactImporter = new ContactImporter(Login, txtPassword.Text, emailCat.SelectedValue); contactImporter.login(); LoginOkay = contactImporter.logged_in; if (LoginOkay) { try { contactImporter.getcontacts(); fetch = DateTime.Now - start; } catch { } this.nameArray = contactImporter.nameArray; this.emailArray = contactImporter.emailArray; for (int i = 0; i < emailArray.Length; i++) { emailArray[i] = emailArray[i].ToLower(); } string ImportToken = Next2Friends.Misc.UniqueID.NewWebID(); //insert into the db so they can be referenced by JoinEmailsWithMembers for (int i = 0; i < emailArray.Length; i++) { ContactImport contact = new ContactImport(); contact.WebID = Next2Friends.Misc.UniqueID.NewWebID(); contact.ImporterMemberID = member.MemberID; contact.Email = emailArray[i]; contact.Name = nameArray[i]; contact.FriendState = (int)FriendState.None; contact.InviteState = (int)InviteState.None; contact.ImportToken = ImportToken; contact.IsInitialImport = 1; contact.SaveWithCheck(); } FullContacts = new List <ContactImport>(); List <ContactImport> MemberList = new List <ContactImport>(); //List<ContactImport> ExistingContactList = ContactImport.GetAllContactImportByMemberID(member.MemberID); if (emailArray.Length > 0) { MemberList = ContactImport.JoinEmailsWithMembers(member.MemberID, emailArray, ImportToken); } List <Member> FriendList = Member.GetAllFriendsByMemberID(member.MemberID); for (int i = 0; i < emailArray.Length; i++) { int friendState = (int)FriendState.None; int inviteState = (int)InviteState.None; ContactImport Associcate = MemberList.FirstOrDefault(f => f.Email == emailArray[i]); if (Associcate != null) { friendState = Associcate.FriendState; inviteState = Associcate.InviteState; } ContactImport contact = new ContactImport(); contact.WebID = Next2Friends.Misc.UniqueID.NewWebID(); contact.ImporterMemberID = member.MemberID; contact.Email = emailArray[i]; contact.Name = nameArray[i]; contact.FriendState = friendState; contact.InviteState = inviteState; FullContacts.Add(contact); } var sortedContacts = from c in FullContacts where c.Email != string.Empty orderby c.Name select c; FullContacts = sortedContacts.ToList(); Imported = true; ImportCount = FullContacts.Count; Session["Contacts"] = FullContacts; BuildContactList(); ImportStage = true; HelperMessage = "<p style='color:#0257AE'>You may now choose your contacts to invite</p>"; } else { BuildLetterIndexList(); Session["Contacts"] = null; HelperMessage = "<p style='color:red;'>Login details are incorrect, please try again</p>"; } }