public static bool HasCredentials(string username) { using (var db = new AspNetDatingDataContext()) { return db.FacebookCredentials.Any(tc => tc.u_username == username); } }
public static void PublishTweet(string username, string tweet) { using (var db = new AspNetDatingDataContext()) { var credentials = db.TwitterCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials == null) return; // encode the username/password string user = Convert.ToBase64String( System.Text.Encoding.UTF8.GetBytes(credentials.tc_username + ":" + credentials.tc_password)); // determine what we want to upload as a status byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet); // connect with the update page var request = (HttpWebRequest) WebRequest.Create("https://twitter.com/statuses/update.xml"); // set the method to POST request.Method = "POST"; // thanks to argodev for this recent change! request.ServicePoint.Expect100Continue = false; // set the authorisation levels request.Headers.Add("Authorization", "Basic " + user); request.ContentType = "application/x-www-form-urlencoded"; // set the length of the content request.ContentLength = bytes.Length; // set up the stream Stream reqStream = request.GetRequestStream(); // write to the stream reqStream.Write(bytes, 0, bytes.Length); // close the stream reqStream.Close(); } }
public static double FetchAverageNumberOfVotes(TimeSpan period, User.eGender gender, int minAge, int maxAge) { string cacheKey = String.Format("Votes_FetchAverageNumberOfVotes_{0}_{1}_{2}_{3}", period, gender, minAge, maxAge); if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return (double)HttpContext.Current.Cache[cacheKey]; } double average; var fromDate = DateTime.Now.Subtract(period); DateTime fromBirthdate = DateTime.Now.Subtract(TimeSpan.FromDays((maxAge + 1) * 365.25)); DateTime toBirthdate = DateTime.Now.Subtract(TimeSpan.FromDays(minAge * 365.25)); using (var db = new AspNetDatingDataContext()) { average = (from v in db.Votes join u in db.Users on v.v_tousername equals u.u_username where v.v_timestamp >= fromDate && u.u_gender == (int)gender && u.u_birthdate >= fromBirthdate && u.u_birthdate <= toBirthdate group v by v.v_tousername into uv select (double?) uv.Count()).Average() ?? 0; } if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert(cacheKey, average, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null); } return average; }
/// <summary> /// Saves this instance. /// </summary> public void Save() { using (var db = new AspNetDatingDataContext()) { var photoNote = new Model.PhotoNote { pn_id = Id, p_id = PhotoId, u_username = Username, pn_notes = Notes, pn_timestamp = Timestamp, pn_x = X, pn_y = Y, pn_width = Width, pn_height = Height }; if (Id == 0) db.PhotoNotes.InsertOnSubmit(photoNote); else { db.PhotoNotes.Attach(photoNote, true); } db.SubmitChanges(); if (Id == 0) Id = photoNote.pn_id; } }
public static void Delete(int id) { using (var db = new AspNetDatingDataContext()) { var eventComment = db.EventComments.Single(c => c.ec_id == id); db.EventComments.DeleteOnSubmit(eventComment); db.SubmitChanges(); } }
public static void Delete(int id) { using (var db = new AspNetDatingDataContext()) { var pollChoice = db.PollChoices.FirstOrDefault(pc => pc.pc_id == id); if (pollChoice != null) { db.PollChoices.DeleteOnSubmit(pollChoice); db.SubmitChanges(); } } }
public static void RemoveCredentials(string username) { using (var db = new AspNetDatingDataContext()) { var credentials = db.FacebookCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials != null) { db.FacebookCredentials.DeleteOnSubmit(credentials); db.SubmitChanges(); } } }
public static PollChoice[] FetchByPollID(int pollID) { using (var db = new AspNetDatingDataContext()) { return (from pc in db.PollChoices where pc.p_id == pollID select new PollChoice { ID = pc.pc_id, PollID = pc.p_id, Answer = pc.pc_answer }).ToArray(); } }
public static PollChoice Fetch(int choiceID) { using (var db = new AspNetDatingDataContext()) { return (from pc in db.PollChoices where pc.pc_id == choiceID select new PollChoice { ID = pc.pc_id, PollID = pc.p_id, Answer = pc.pc_answer }).FirstOrDefault(); } }
public static void PublishStatus(string username, long facebookId, string status) { using (var db = new AspNetDatingDataContext()) { var credentials = db.FacebookCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials == null) return; using (var client = new WebClient()) { var fields = new NameValueCollection {{"access_token", credentials.fc_token}, {"message", status}}; client.UploadValues(string.Format("https://graph.facebook.com/{0}/feed", facebookId), fields); } } }
public static void Delete(int id) { using (var db = new AspNetDatingDataContext()) { var pollAnswers = db.PollAnswers.Where(pa => pa.p_id == id); var pollChoices = db.PollChoices.Where(pc => pc.p_id == id); var poll = db.Polls.FirstOrDefault(p => p.p_id == id); if (poll != null) { db.PollAnswers.DeleteAllOnSubmit(pollAnswers); db.PollChoices.DeleteAllOnSubmit(pollChoices); db.Polls.DeleteOnSubmit(poll); db.SubmitChanges(); } } }
public static void AddAnswer(int pollID, string username, int choiceID) { using (var db = new AspNetDatingDataContext()) { var pollAnswer = new Model.PollAnswer { p_id = pollID, pc_id = choiceID, u_username = username }; db.PollAnswers.InsertOnSubmit(pollAnswer); db.SubmitChanges(); } }
public static void SaveCredentials(string username, string token) { using (var db = new AspNetDatingDataContext()) { var credentials = db.FacebookCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials == null) { credentials = new FacebookCredential { u_username = username }; db.FacebookCredentials.InsertOnSubmit(credentials); } credentials.fc_token = token; db.SubmitChanges(); } }
public static Dictionary<string, double> FetchTopUsers(User.eGender gender, int minAge, int maxAge, TimeSpan period, int count) { DateTime fromBirthdate = DateTime.Now.Subtract(TimeSpan.FromDays((maxAge + 1) * 365.25)); DateTime toBirthdate = DateTime.Now.Subtract(TimeSpan.FromDays(minAge * 365.25)); string cacheKey = String.Format("Votes_FetchTopUsers_{0}_{1}_{2}_{3}_{4}", gender, minAge, maxAge, period, count); if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return (Dictionary<string, double>) HttpContext.Current.Cache[cacheKey]; } var userRatings = new Dictionary<string, double>(); var fromDate = DateTime.Now.Subtract(period); var averageRating = FetchAverageRating(period, gender, minAge, maxAge); var averageNumberOfVotes = FetchAverageNumberOfVotes(period, gender, minAge, maxAge); using (var db = new AspNetDatingDataContext()) { foreach (var rating in (from v in db.Votes join u in db.Users on v.v_tousername equals u.u_username where v.v_timestamp >= fromDate && u.u_gender == (int) gender && u.u_birthdate >= fromBirthdate && u.u_birthdate <= toBirthdate group v by v.v_tousername into uv select new { Username = uv.Key, Rating = ((averageNumberOfVotes*averageRating) + (uv.Count()*uv.Average(v => v.v_score))) /(averageNumberOfVotes + uv.Count()) }).OrderByDescending( uv => uv.Rating).Take(count)) { userRatings.Add(rating.Username, rating.Rating); } } if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert(cacheKey, userRatings, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null); } return userRatings; }
public static void SaveCredentials(string username, string twitterUsername, string twitterPassword) { using (var db = new AspNetDatingDataContext()) { var credentials = db.TwitterCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials == null) { credentials = new TwitterCredential {u_username = username}; db.TwitterCredentials.InsertOnSubmit(credentials); } credentials.tc_username = twitterUsername; credentials.tc_password = twitterPassword; db.SubmitChanges(); } }
public static void PublishTweet(string username, string tweet) { using (var db = new AspNetDatingDataContext()) { var credentials = db.TwitterCredentials.FirstOrDefault(tc => tc.u_username == username); if (credentials == null) return; string url = ""; string xml = ""; oAuthTwitter oAuth = new oAuthTwitter(); oAuth.Token = credentials.tc_username; oAuth.TokenSecret = credentials.tc_password; //POST url = "http://twitter.com/statuses/update.xml"; xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.POST, url, "status=" + oAuth.UrlEncode(tweet)); } }
/// <summary> /// Loads the specified id. /// </summary> /// <param name="id">The id.</param> /// <param name="photoId">The photo id.</param> /// <param name="username">The username.</param> /// <returns></returns> public static PhotoNote[] Load(int? id, int? photoId, string username) { using (var db = new AspNetDatingDataContext()) { var photoNotes = from pn in db.PhotoNotes where (!id.HasValue || pn.pn_id == id) && (!photoId.HasValue || pn.p_id == photoId) && (username == null || pn.u_username == username) select new PhotoNote { Id = pn.pn_id, PhotoId = pn.p_id, Username = pn.u_username, Notes = pn.pn_notes, Timestamp = pn.pn_timestamp, X = pn.pn_x, Y = pn.pn_y, Width = pn.pn_width, Height = pn.pn_height }; return photoNotes.ToArray(); } }
public void Save() { using (var db = new AspNetDatingDataContext()) { var pollChoice = new Model.PollChoice { p_id = PollID, pc_id = ID, pc_answer = Answer }; if (ID == 0) db.PollChoices.InsertOnSubmit(pollChoice); else { db.PollChoices.Attach(pollChoice, true); } db.SubmitChanges(); if (ID == 0) ID = pollChoice.pc_id; } }
private static Relationship[] Fetch(string fromUsername, string toUsername, eRelationshipStatus? type, bool? accepted) { using (var db = new AspNetDatingDataContext()) { var relationships = (from r in db.Relationships where (fromUsername == null || r.u_username == fromUsername) && (toUsername == null || r.r_username == toUsername) && (!type.HasValue || (eRelationshipStatus?) r.r_type == type) && (!accepted.HasValue || r.r_accepted == accepted) select new Relationship { id = r.r_id, fromUsername = r.u_username, toUsername = r.r_username, accepted = r.r_accepted, timestamp = r.r_timestamp, type = (eRelationshipStatus) r.r_type, pendingType = (eRelationshipStatus) r.r_pendingtype }); return relationships.ToArray(); } }
public static string[] FetchRequests(string toUsername) { using (var db = new AspNetDatingDataContext()) { var result = from r in db.Relationships where (r.r_username == toUsername && (!r.r_accepted || r.r_pendingtype != null)) select r.u_username; return result.ToArray(); } }
private static void Delete(int? id, string fromUsername, string toUsername, bool? accepted) { using (var db = new AspNetDatingDataContext()) { var relationship = db.Relationships.Where( r => (!id.HasValue || r.r_id == id) && (fromUsername == null || r.u_username == fromUsername) && (toUsername == null || r.r_username == toUsername) && (!accepted.HasValue || r.r_accepted == accepted)).ToArray(); db.Relationships.DeleteAllOnSubmit(relationship); db.SubmitChanges(); } }
public void Save() { using (var db = new AspNetDatingDataContext()) { var relationship = new Model.Relationship() { r_id = id, u_username = fromUsername, r_username = toUsername, r_type = (int) type, r_pendingtype = pendingType.HasValue ? (int?) pendingType : null, r_accepted = accepted, r_timestamp = timestamp }; if (id == 0) { db.Relationships.InsertOnSubmit(relationship); } else { db.Relationships.Attach(relationship, true); } db.SubmitChanges(); if (id == 0) id = relationship.r_id; } }
public static void DeleteByEventID(int id) { using (var db = new AspNetDatingDataContext()) { var comments = db.EventComments.Where(c => c.e_id == id); db.EventComments.DeleteAllOnSubmit(comments); db.SubmitChanges(); } }
public static string GetViewedUserDisplayedNameByUsername(string viewer, string viewed) { if (viewed == viewer) { return User.Load(viewer).Name; } else if (User.Load(viewer).Paid) { return User.Load(viewed).Name; } else { var displayName = String.Empty; using (var db = new AspNetDatingDataContext()) { displayName = CompiledQueries.FetchDisplayedName(db, viewer, viewed); } if (displayName.IsNullOrEmpty()) { displayName = User.Load(viewed).Name; if (displayName.Length > 4) displayName = displayName.Substring(0, 4) + "..."; } return displayName; } }
private void LoadPhotosOfFriendsWithMutualFriends(HttpContext context) { CacheImagesOfFriends(context, ImageHandler.eFacebookImageType.Large); var friendsIDsWithMutualFriends = ((List<MutualFriendItem>)HttpContext.Current.GetSession()["FacebookMutualFriends"]) .Select(f => f.FriendID).Distinct().ToList(); DateTime[] time = new DateTime[5]; time[0] = DateTime.Now; if (friendsIDsWithMutualFriends != null && Classes.User.IsUsernameTaken(friendsIDsWithMutualFriends.Last().ToString())) { var lstFriendsIds = new List<long>(); try { // fetch facebook friends without images using (var db = new AspNetDatingDataContext()) { var tmpList = CompiledQueries.FetchActiveFriendsForUsername(db, MatchmakerHelper.CurrentUsername).ToList(); var tmpArray = tmpList.Where( f => f.User1.u_logincount == 0 && f.User1.u_facebookid.HasValue && !f.User1.u_face_control_approved) .OrderBy(f => f.User1.u_name).Select(f => f.User1.u_facebookid.Value).ToArray(); foreach (var un in tmpArray) { int imgId = Photo.GetPrimaryOrDefaultId(un.ToString()); if (imgId < 0) lstFriendsIds.Add(un); if (lstFriendsIds.Count > 60) break; } } } catch (Exception ex) { } if (lstFriendsIds.Count > 0) { try { var parameterizedThreadsList = new Classes.LoveHitchParallel.ParameterizedThreadsList<long>( lstFriendsIds, (new FacebookHelper.FetchAndSaveSaveFacebookFriendImageClass()). FetchAndSaveFacebookImageByFacebookId, context); parameterizedThreadsList.RunAsBackgroundThreads = true; parameterizedThreadsList.ExecuteParallelWork(10); } catch (Exception ex) { } } else { context.Session["SessionRefreshState"] = SessionRefreshStateEnum.AddFriendsWithoutMutualFriends; FacebookHelper.AddFriends(PageBase.GetCurrentUserSession(), 100, context, null); } } else { context.Session["SessionRefreshState"] = SessionRefreshStateEnum.AddFriendsWithMutualFriends; FacebookHelper.AddFriends(PageBase.GetCurrentUserSession(), 0, context, null); } }
public static void Delete(int id) { using (var db = new AspNetDatingDataContext()) { var bannerCode = db.BannerCodes.Single(c => c.bc_id == id); db.BannerCodes.DeleteOnSubmit(bannerCode); db.SubmitChanges(); CacheDependencies.NotifyChanged(); } }
public void Save() { using (var db = new AspNetDatingDataContext()) { var bannerCode = new Model.BannerCode() { bc_id = id, bc_position = (int) position, bc_priority = priority, bc_target = target, bc_code = code }; if (id == 0) { db.BannerCodes.InsertOnSubmit(bannerCode); } else { db.BannerCodes.Attach(bannerCode, true); } db.SubmitChanges(); if (id == 0) id = bannerCode.bc_id; CacheDependencies.NotifyChanged(); } }
public void Save() { if (comment != null && comment.Length > 2000) { Global.Logger.LogWarning( String.Format("EventComment {0} was not saved because it is more than 2000 chars", id)); return; } using (var db = new AspNetDatingDataContext()) { var eventComment = new Model.EventComment() { ec_id = id, e_id = eventID, u_username = username, ec_date = date, ec_comment = comment }; if (id == 0) db.EventComments.InsertOnSubmit(eventComment); else { db.EventComments.Attach(eventComment, true); } db.SubmitChanges(); if (id == 0) id = eventComment.ec_id; } }
private void LoadPhotosOfFriendsWithoutMutualFriends(HttpContext context) { IList<FacebookHelper.FacebookFriendData> friendsData = FacebookHelper.GetFriendsDataList(context); if (Classes.User.IsUsernameTaken(friendsData.Last().Username)) { var lstFriendsIds = new List<long>(); try { // fetch facebook friends without images using (var db = new AspNetDatingDataContext()) { var tmpList = CompiledQueries.FetchActiveFriendsForUsername(db, MatchmakerHelper.CurrentUsername).ToList(); var tmpArray = tmpList.Where( f => f.User1.u_logincount == 0 && f.User1.u_facebookid.HasValue && !f.User1.u_face_control_approved) .OrderBy(f => f.User1.u_name).Select(f => f.User1.u_facebookid.Value).ToArray(); foreach (var un in tmpArray) { int imgId = Photo.GetPrimaryOrDefaultId(un.ToString()); if (imgId < 0) lstFriendsIds.Add(un); if (lstFriendsIds.Count > 100) break; } } } catch (Exception ex) { } if (!FacebookHelper.IsCurrentSessionConnected || lstFriendsIds.Count <= 0) return; try { var parameterizedThreadsList = new Classes.LoveHitchParallel.ParameterizedThreadsList<long>( lstFriendsIds, (new FacebookHelper.FetchAndSaveSaveFacebookFriendImageClass()).FetchAndSaveFacebookImageByFacebookId, context); parameterizedThreadsList.RunAsBackgroundThreads = true; parameterizedThreadsList.ExecuteParallelWork(10); } catch (Exception ex) { } } else { context.Session["SessionRefreshState"] = SessionRefreshStateEnum.AddFriendsWithoutMutualFriends; } }
private static EventComment[] Fetch(int? id, int? eventID, string username, int? numberOfComments, eSortColumn sortColumn) { using (var db = new AspNetDatingDataContext()) { var comments = from c in db.EventComments where (!id.HasValue || c.ec_id == id) && (!eventID.HasValue || eventID == c.e_id) && (username == null || username == c.u_username) select new EventComment { id = c.ec_id, eventID = c.e_id, username = c.u_username, comment = c.ec_comment, date = c.ec_date }; if (sortColumn == eSortColumn.Date) { comments = comments.OrderByDescending(c => c.date); } else if (sortColumn == eSortColumn.Username) { comments = comments.OrderBy(c => c.username); } else if (sortColumn == eSortColumn.EventID) { comments = comments.OrderBy(c => c.eventID); } if (numberOfComments.HasValue) { comments = comments.Take(numberOfComments.Value); } return comments.ToArray(); } }