Exemplo n.º 1
0
        /// <summary>
        /// Loads SavedSearch array from database by specified id, username and name.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="username">The username.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private static SavedSearch[] Load(object id, string username, string name, object emailMatches)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = (SqlDataReader)
                    SqlHelper.GetDB().ExecuteReader( "LoadSavedSearch", id, username, name, emailMatches);

                SavedSearch savedSearch = null;

                List<SavedSearch> lSavedSearches = new List<SavedSearch>();
                while (reader.Read())
                {
                    savedSearch = new SavedSearch();

                    savedSearch.id = (int)reader["ID"];
                    savedSearch.username = (string)reader["Username"];
                    savedSearch.name = (string)reader["Name"];
                    savedSearch.gender = (User.eGender)reader["Gender"];
                    savedSearch.country = (string)reader["Country"];
                    savedSearch.state = (string)reader["State"];
                    savedSearch.zip = (string)reader["Zip"];
                    savedSearch.city = (string)reader["City"];
                    savedSearch.ageFrom = (int)reader["AgeFrom"];
                    savedSearch.ageTo = (int)reader["AgeTo"];
                    savedSearch.photoRequired = (bool)reader["PhotoRequired"];
                    string xmlIds = (string)reader["ChoiceIDs"];

                    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlIds));
                    XmlSerializer xmls = new XmlSerializer(typeof(int[]));
                    savedSearch.choiceIds = (int[])xmls.Deserialize(ms);

                    savedSearch.emailMatches = (bool)reader["EmailMatches"];
                    savedSearch.emailFrequency = (int)reader["EmailFrequency"];
                    savedSearch.nextEmailDate = reader["NextEmailDate"] == DBNull.Value ? null : (DateTime?)reader["NextEmailDate"];

                    lSavedSearches.Add(savedSearch);
                }
                return lSavedSearches.ToArray();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates Saved Search object with id = -1.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="name">The name.</param>
        /// <param name="gender">The gender.</param>
        /// <param name="country">The country.</param>
        /// <param name="state">The state.</param>
        /// <param name="zip">The zip.</param>
        /// <param name="city">The city.</param>
        /// <param name="ageFrom">The age from.</param>
        /// <param name="ageTo">The age to.</param>
        /// <param name="photoRequired">if set to <c>true</c> [photo required].</param>
        /// <param name="choiceIds">The choice ids.</param>
        /// <returns>SavedSearch object</returns>
        public static SavedSearch Create(string username, string name, User.eGender gender,
                                         string country, string state, string zip, string city, int ageFrom,
                                         int ageTo, bool photoRequired, int[] choiceIds,
                                         bool emailMatches, int emailFrequency, DateTime? nextEmailDate)
        {
            SavedSearch ss = new SavedSearch();

            ss.username = username;
            ss.name = name;
            ss.gender = gender;
            ss.country = country;
            ss.state = state;
            ss.zip = zip;
            ss.city = city;
            ss.ageFrom = ageFrom;
            ss.ageTo = ageTo;
            ss.photoRequired = photoRequired;
            ss.choiceIds = choiceIds;
            ss.emailMatches = emailMatches;
            ss.emailFrequency = emailFrequency;
            ss.nextEmailDate = nextEmailDate;

            return ss;
        }