コード例 #1
0
        public JsonResult ImportContacts(Attachment attachment)
        {
            var text = Encoding.UTF8.GetString(attachment.Content);
            var contacts = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
            if (contacts.Count < 2)
            {
                return Json(false);
            }

            var indexes = Indexes.IndexString(contacts[0]);
            contacts.RemoveAt(0);
            foreach (var contactText in contacts)
            {
                var parts = contactText.Split(new [] { "," }, StringSplitOptions.None);
                var contact = new Contact
                {
                    Email = parts[indexes.Email],
                    FirstName = parts[indexes.FirstName],
                    LastName = parts[indexes.LastName],
                    MiddleName = parts[indexes.MiddleName],
                    Organization = parts[indexes.Organization]
                };
                if (User.Contacts.Any(x => x.Email == contact.Email))
                {
                    continue;
                }

                var groups = parts[indexes.Grouops].Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var groupName in groups)
                {
                    var group = User.ContactsGroups.FirstOrDefault(x => x.Name.ToLower() == groupName.ToLower());
                    if (group == null)
                    {
                        group = new ContactsGroup { Name = groupName };
                        User.AddContactsGroup(group);
                    }

                    contact.AddGroup(group);
                }

                User.AddContact(contact);
            }

            return Json(true);
        }
コード例 #2
0
ファイル: Contact.cs プロジェクト: feafarot/fMailer
 public virtual void AddGroup(ContactsGroup group)
 {
     Groups.Add(group);
 }
コード例 #3
0
 private void TryAddGroupToContact(Contact contact, ContactsGroup group)
 {
     if (contact.Groups.FirstOrDefault(x => x.Id == group.Id) == null)
     {
         if (group.Id < 1)
         {
             group.Id = 0;
             User.AddContactsGroup(group);
             contact.AddGroup(group);
         }
         else
         {
             var realGroup = User.ContactsGroups.First(x => x.Id == group.Id);
             contact.AddGroup(realGroup);
         }
     }
 }
コード例 #4
0
ファイル: User.cs プロジェクト: feafarot/fMailer
 public virtual void AddContactsGroup(ContactsGroup group)
 {
     group.User = this;
     ContactsGroups.Add(group);
 }