private void bindAnswers(ProfileAnswer[] answers) { dgPendingApproval.Columns[0].HeaderText = Lang.TransA("Username"); dgPendingApproval.Columns[1].HeaderText = Lang.TransA("Question"); dgPendingApproval.Columns[2].HeaderText = Lang.TransA("Answer"); DataTable dtAnswers = new DataTable("Answers"); dtAnswers.Columns.Add("Username"); dtAnswers.Columns.Add("Question"); dtAnswers.Columns.Add("Answer"); dtAnswers.Columns.Add("QuestionID"); foreach (ProfileAnswer answer in answers) { dtAnswers.Rows.Add(new object[] { answer.User.Username, answer.Question.Name, answer.Value.Length > 300 ? Server.HtmlEncode(answer.Value.Substring(0, 300)) + "..." : Server.HtmlEncode(answer.Value), answer.Question.Id } ); } dtAnswers.DefaultView.Sort = "Username"; dgPendingApproval.DataSource = dtAnswers; try { dgPendingApproval.DataBind(); } catch (HttpException) { dgPendingApproval.CurrentPageIndex = 0; dgPendingApproval.DataBind(); } }
private void createUser(User user, string name, string status, User.eGender gender, User.eGender interestedIn, int ipIdx, int age, string img1, string img2) { var username = name.Replace(" ", "").Substring(0, 4) + age; var random = new Random((int)(DateTime.Now.Ticks % int.MaxValue)); int day = random.Next(1, 28); int month = random.Next(1, 12); int year = DateTime.Now.Year - age; if (!Classes.User.IsUsernameTaken(username)) { user.Username = username; user.Password = username; user.Name = name; user.Gender = gender; user.InterestedIn = interestedIn; user.StatusText = status; user.Email = String.Format("{0}@ezFixUp.com", username); user.Birthdate = new DateTime(year, month, day); Classes.User.Create(user, String.Format("192.168.{0}.{1}", ipIdx / 255, ipIdx % 255)); ProfileTopic[] topics = ProfileTopic.Fetch(); foreach (ProfileTopic profileTopic in topics) { ProfileQuestion[] questions = profileTopic.FetchQuestions(); foreach (ProfileQuestion profileQuestion in questions) { try { var existAnswer = ProfileAnswer.Fetch(username, profileQuestion.Id); if (existAnswer != null) continue; } catch { ProfileChoice[] choices = profileQuestion.FetchChoices(); if (choices != null && choices.Length > 0) { var answer = new ProfileAnswer(username, profileQuestion.Id) { Value = choices[random.Next(choices.Length - 1)].Value }; try { answer.Save(); } catch (Exception ex) { } } } } } } else { user = Classes.User.Load(username); } if (user != null && user.SignupIp.IsNotNullOrEmpty() && user.SignupIp.StartsWith("192.168.")) { user.updateLastLogin(DateTime.Now.Ticks.ToString()); var pathTemplate = Config.Directories.Home + @"\images\profiles\{0}.jpg"; if (img1.Trim().IsNotNullOrEmpty()) StoreUserPhoto(user, String.Format(pathTemplate, img1), true); if (img2.IsNotNullOrEmpty()) StoreUserPhoto(user, String.Format(pathTemplate, img2), false); } }
private void rejectAnswer(ProfileAnswer answer) { try { ProfileAnswer oldAnswer = ProfileAnswer.Fetch(answer.User.Username, answer.Question.Id); if (oldAnswer.Value != answer.Value || !oldAnswer.Approved) { answer.Approved = false; } } catch (NotFoundException) { answer.Approved = false; } }
public static ProfileAnswer[] FetchNonApproved() { //using (var conn = Config.DB.Open()) { var lAnswers = new List<ProfileAnswer>(); using (var reader = SqlHelper.GetDB().ExecuteReader("FetchNonApprovedAnswers")) { while (reader.Read()) { var answer = new ProfileAnswer { questionId = ((int) reader["QuestionID"]), username = ((string) reader["Username"]), _value = ((string) reader["Value"]), approved = ((bool) reader["Approved"]) }; lAnswers.Add(answer); } reader.Close(); } return lAnswers.ToArray(); } }
/// <summary> /// Fetches Profile Answers from the DB for the specified topic /// </summary> /// <param name="Username">ID of the question</param> /// <returns>Array of ProfileAnswer objects</returns> public static ProfileAnswer[] FetchByUsername(string Username) { string cacheKey = String.Format("ProfileAnswer_Fetch_{0}", Username); if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return HttpContext.Current.Cache[cacheKey] as ProfileAnswer[]; } //using (var conn = Config.DB.Open()) { var lAnswers = new List<ProfileAnswer>(); using (var reader = SqlHelper.GetDB().ExecuteReader("FetchProfileAnswerByUser", Username)) { while (reader.Read()) { var answer = new ProfileAnswer { username = Username, questionId = ((int) reader["QuestionID"]), _value = ((string) reader["Value"]), approved = ((bool) reader["Approved"]) }; lAnswers.Add(answer); } reader.Close(); } ProfileAnswer[] answers = null; if (lAnswers.Count > 0) { answers = lAnswers.ToArray(); } if (HttpContext.Current != null && answers != null) { HttpContext.Current.Cache.Insert(cacheKey, answers, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15), CacheItemPriority.NotRemovable, null); } return answers; } }
/// <summary> /// Fetches Profile Answers from the DB for the specified topic /// </summary> /// <param name="QuestionID">ID of the question</param> /// <returns>Array of ProfileAnswer objects</returns> public static ProfileAnswer[] FetchByQuestionID(int QuestionID) { //using (var conn = Config.DB.Open()) { var lAnswers = new List<ProfileAnswer>(); using (var reader = SqlHelper.GetDB().ExecuteReader("FetchProfileAnswerByQuestion", QuestionID)) { while (reader.Read()) { var answer = new ProfileAnswer { questionId = QuestionID, username = ((string) reader["Username"]), _value = ((string) reader["Value"]), approved = ((bool) reader["Approved"]) }; lAnswers.Add(answer); } reader.Close(); } if (lAnswers.Count > 0) { return lAnswers.ToArray(); } return null; } }
/// <summary> /// Fetches profile answer by user and question /// </summary> /// <param name="Username">Username</param> /// <param name="QuestionID">ID of the Question</param> /// <returns>ProfileAnswer object</returns> public static ProfileAnswer Fetch(string Username, int QuestionID) { string cacheKey = String.Format("ProfileAnswer_Fetch_{0}_{1}", Username, QuestionID); if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null) { return HttpContext.Current.Cache[cacheKey] as ProfileAnswer; } //using (var conn = Config.DB.Open()) { var answer = new ProfileAnswer { username = Username, questionId = QuestionID }; using (var reader = SqlHelper.GetDB().ExecuteReader("FetchProfileAnswer", Username, QuestionID)) { if (reader.Read()) { answer._value = (string) reader["Value"]; answer.approved = (bool) reader["Approved"]; reader.Close(); } else { throw new NotFoundException (Lang.Trans("The requested answer does not exist!")); } } if (HttpContext.Current != null) { HttpContext.Current.Cache.Insert(cacheKey, answer, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(15), CacheItemPriority.NotRemovable, null); } return answer; } }
private void createUser(User user, string username, string status, User.eGender gender, User.eGender interestedIn, int ipIdx) { if (!Classes.User.IsUsernameTaken(username)) { user.Username = username; user.Password = username; user.Name = String.Format("{0} {1}{2}", status, gender, user.Age); user.Gender = gender; user.InterestedIn = interestedIn; user.StatusText = status; user.Email = String.Format("{0}@ezFixUp.com", username); Classes.User.Create(user, String.Format("192.168.{0}.{1}", ipIdx/255, ipIdx%255)); } var random = new Random((int)(DateTime.Now.Ticks%int.MaxValue)); ProfileTopic[] topics = ProfileTopic.Fetch(); foreach (ProfileTopic profileTopic in topics) { ProfileQuestion[] questions = profileTopic.FetchQuestions(); foreach (ProfileQuestion profileQuestion in questions) { try { var existAnswer = ProfileAnswer.Fetch(username, profileQuestion.Id); if (existAnswer != null) continue; } catch { ProfileChoice[] choices = profileQuestion.FetchChoices(); if (choices!=null&&choices.Length > 0) { var answer = new ProfileAnswer(username, profileQuestion.Id) { Value = choices[random.Next(choices.Length - 1)].Value }; answer.Save(); } } } } }
protected void btnSaveAndApprove_Click(object sender, EventArgs e) { if (!HasWriteAccess) return; ProfileAnswer answer = new ProfileAnswer(username, questionID); if (txtAnswer.Text.Trim() == String.Empty) btnReject_Click(null, null); else answer.Value = txtAnswer.Text; answer.Approved = true; answer.Save(); #region Add FriendUpdatedProfile Event Event newEvent = new Event(username); newEvent.Type = Event.eType.FriendUpdatedProfile; UpdatedProfile updatedProfile = new UpdatedProfile(); updatedProfile.QuestionIDs = new List<int>() {answer.Question.Id }; newEvent.DetailsXML = Misc.ToXml(updatedProfile); newEvent.Save(); string[] usernames = Classes.User.FetchMutuallyFriends(username); foreach (string friendUsername in usernames) { if (Config.Users.NewEventNotification) { string text = String.Format("Your friend {0} has updated the \"{1}\" section in their profile".TranslateA(), "<b>" + username + "</b>", answer.Question.Name); int imageID = 0; try { imageID = Photo.GetPrimary(username).Id; } catch (NotFoundException) { User user = null; try { user = Classes.User.Load(username); imageID = ImageHandler.GetPhotoIdByGender(user.Gender); } catch (NotFoundException) { break; } } string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true); Classes.User.SendOnlineEventNotification(username, friendUsername, text, thumbnailUrl, UrlRewrite.CreateShowUserUrl(username)); } } #endregion Response.Redirect("ApproveAnswers.aspx"); }
private static void AsyncProcessMailerQueue(object data) { if (mailerLock || DateTime.Now.DayOfWeek != DayOfWeek.Friday || !(DateTime.Now.Hour >= 8 && DateTime.Now.Hour <= 10)) { return; } try { mailerLock = true; CustomSearch search = new CustomSearch(); foreach (SavedSearch savedSearchToMail in SavedSearch.GetSavedSearchesToMail()) { User recipient = null; try { recipient = User.Load(savedSearchToMail.Username); if (!recipient.ReceiveEmails || recipient.Deleted) continue; if (recipient.Email.ToLower().Contains("@lovehitch.com")) continue; } catch (NotFoundException) { continue; } search.Gender = savedSearchToMail.Gender; if (Config.Users.InterestedInFieldEnabled) { search.InterestedIn = recipient.Gender; } search.MinAge = savedSearchToMail.AgeFrom; search.MaxAge = savedSearchToMail.AgeTo; search.Country = savedSearchToMail.Country; search.State = savedSearchToMail.State; search.City = savedSearchToMail.City; search.Zip = savedSearchToMail.Zip; if (savedSearchToMail.PhotoRequired) search.HasPhoto = true; search.SortAsc = false; search.SortColumn = "SignupDate"; #region Set Answers int lastQuestionId = -1; List<ProfileAnswer[]> groupedAnswers = new List<ProfileAnswer[]>(); List<ProfileAnswer> profileAnswers = new List<ProfileAnswer>(); foreach (int choiceId in savedSearchToMail.ChoiceIds) { ProfileChoice choice = null; try { choice = ProfileChoice.Fetch(choiceId); } catch (NotFoundException) { continue; } if (lastQuestionId != -1 && choice.Question.Id != lastQuestionId) { if (profileAnswers.Count > 0) groupedAnswers.Add(profileAnswers.ToArray()); profileAnswers.Clear(); } ProfileAnswer answer = new ProfileAnswer(recipient.Username, choice.Question.Id); answer.Value = choice.Value; profileAnswers.Add(answer); if (savedSearchToMail.ChoiceIds[savedSearchToMail.ChoiceIds.Length - 1] == choiceId) { if (profileAnswers.Count > 0) groupedAnswers.Add(profileAnswers.ToArray()); } lastQuestionId = choice.Question.Id; } search.Answers = groupedAnswers.ToArray(); #endregion UserSearchResults results = search.GetResults(); EmailTemplates.SavedSearchMatches matchesTemplate = new EmailTemplates.SavedSearchMatches(recipient.LanguageId); if (results != null && results.Usernames.Length >= matchesTemplate.NumberOfMatchesToMail) { string[] matches = new string[matchesTemplate.NumberOfMatchesToMail]; Array.Copy(results.Usernames, matches, matches.Length); Email.Send(Config.Misc.SiteTitle, Config.Misc.SiteEmail, recipient.Name, recipient.Email, matchesTemplate.GetFormattedSubject(recipient.Name), matchesTemplate.GetFormattedBody(matchesTemplate, recipient.Name, matches), true); savedSearchToMail.SetNextEmailDate(); } } } catch (Exception err) { Global.Logger.LogError("SavedSearchesEmailMatches", err); } finally { mailerLock = false; } }