/*det question and answers of some profile*/ public JsonResult QaProfile() { List <QAProfile> profiles = new List <QAProfile>(); try { var customer = EngineContext.Current.Resolve <IWorkContext>().CurrentCustomer; var cs = new DataSettingsManager().LoadSettings().DataConnectionString; using (SqlConnection conn = new SqlConnection(cs)) { using (SqlCommand cmd = new SqlCommand("dbo.P_QAGetProfile", conn)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@CustomerId", SqlDbType.Int).Value = customer.Id;; conn.Open(); var rdr = cmd.ExecuteReader(); Int32 id = 0; QAProfile profile = null; while (rdr.Read()) { if (rdr.GetInt32(0) != id) { if (profile != null) { profiles.Add(profile); } id = rdr.GetInt32(0); profile = new QAProfile { ProfileId = id, Name = rdr.GetString(1) }; } if (rdr.IsDBNull(2)) { continue; /*jump to next iteration of while*/ } ProfileAnswer profileAnswer = new ProfileAnswer { QuestionId = rdr.GetInt32(2), AnswerId = rdr.GetInt32(3) }; profile?.ProfileAnswers.Add(profileAnswer); } rdr.Close(); if (profile != null) { profiles.Add(profile); } } } } catch (Exception ex) { return(Json(new { success = false, msg = ex.Message, profiles = "" }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = true, msg = "", profiles = profiles }, JsonRequestBehavior.AllowGet)); /* * var requestedETag = Request.Headers["If-None-Match"]; * var responseETag = "1e"; // lookup or generate etag however you want * if (requestedETag == responseETag) * return new HttpStatusCodeResult(HttpStatusCode.NotModified); * * Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate); * Response.Cache.SetETag(responseETag); * * //if (Request.Headers["If-Modified-Since"] != null && Count % 2 == 0) * //{ * // return new HttpStatusCodeResult((int)HttpStatusCode.NotModified); * //} * * //Response.Cache.SetExpires(DateTime.Now.AddSeconds(5)); * //Response.Cache.SetLastModified(DateTime.Now); */ }
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; } }