public Message(user targetuser, user sender, long subdomainid) { if (!string.IsNullOrEmpty(targetuser.email)) { transportType = TransportType.EMAIL; destEmail = targetuser.email; } else if (!string.IsNullOrEmpty(targetuser.proxiedEmail)) { transportType = TransportType.EMAIL; destEmail = targetuser.proxiedEmail; } else if (!string.IsNullOrEmpty(targetuser.FBID)) { transportType = TransportType.FACEBOOK; destFbid = long.Parse(targetuser.FBID); } this.sender = sender; this.subdomainid = subdomainid; recipientid = targetuser.id; recipientname = targetuser.ToFullName(); }
public void ImportFacebookContacts() { var query = string.Format( "SELECT uid, first_name, last_name, current_location, pic_big, profile_url, proxied_email, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = {0})", api.Application.Session.UserId); var rows = api.Fql.Query <users_getInfo_response>(query); foreach (var row in rows.user) { try { var usr = repository.GetUserByFBID(row.uid.Value.ToString(), subdomainid); if (usr != null) { continue; } var firstname = row.first_name; var lastname = row.last_name; if (string.IsNullOrEmpty(firstname) && string.IsNullOrEmpty(lastname)) { continue; } var org = new organisation { subdomain = subdomainid, name = string.Format("{0} {1}", firstname, lastname) }; var friend = new user() { role = UserRole.USER.ToInt(), email = "", proxiedEmail = row.proxied_email, firstName = firstname, lastName = lastname, gender = row.sex, organisation = repository.AddOrganisation(org), externalProfilePhoto = row.pic_big, externalProfileUrl = row.profile_url, FBID = row.uid.Value.ToString(), viewid = Crypto.Utility.GetRandomString(), permissions = (int)UserPermission.USER }; repository.UpdateCounters(subdomainid, 1, CounterType.CONTACTS_PRIVATE); repository.AddUser(friend); friend.externalProfilePhoto.ReadAndSaveFromUrl(subdomainid, friend.id, friend.id, PhotoType.PROFILE); } catch (Exception ex) { Syslog.Write(ex); } } // mail user var owner = repository.GetUserById(ownerid, subdomainid); var msg = new message.Message(owner, null, subdomainid); msg.SendMessage(null, repository, EmailViewType.GENERIC, "Your Facebook contacts have been successfully imported", "Import Contacts"); }