예제 #1
0
        public static string RenderImageTag(User.eGender gender, int width, int height, string cssClass,
                                            bool useCache, bool diskCache)
        {
            int photoId = GetPhotoIdByGender(gender);

            return RenderImageTag(photoId, width, height, cssClass, useCache, diskCache);
        }
예제 #2
0
        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 ezFixUpDataContext())
            {
                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;
        }
예제 #3
0
        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 ezFixUpDataContext())
            {
                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;
        }
예제 #4
0
 public static Location GetLocation(User user)
 {
     if (user != null && user.Longitude.HasValue && user.Latitude.HasValue)
     {
         var loc = new Location { Longitude = user.Longitude.Value, Latitude = user.Latitude.Value };
         return loc;
     }
     return null;
 }
예제 #5
0
            public static string[] GetUsersWithinRadius(Location inLocation, bool? hasAnswer, User.eGender gender,
                                                        int maxAge,
                                                        int minAge, bool photoReq, double inRadius,
                                                        int maxResults)
            {
                if (null == inLocation)
                    throw new ArgumentNullException("inLocation", "Null location passed in.");
                if (inRadius <= 0.0)
                    throw new ArgumentOutOfRangeException("inRadius", inRadius, "Invalid value for radius passed in.");

                if (Double.MinValue == inLocation.Latitude)
                    throw new ArgumentException("inLocation.Latitude",
                                                string.Format(
                                                    "The database does not contain latitude information for {0}, {1}.",
                                                    inLocation.City, inLocation.State));
                if (Double.MinValue == inLocation.Longitude)
                    throw new ArgumentException("inLocation.Longitude",
                                                string.Format(
                                                    "The database does not contain longitude information for {0}, {1}.",
                                                    inLocation.City, inLocation.State));

                RadiusBox radBox = RadiusBox.Create(inLocation, inRadius);


                using (SqlConnection conn = DB.Open())
                {
                    SqlDataReader reader = (SqlDataReader)
                        SqlHelper.GetDB().ExecuteReader(
                                                "FetchUsersInRadius",
                                                hasAnswer,
                                                (int)gender,
                                                DateTime.Now.Subtract(TimeSpan.FromDays(maxAge * 365.25)),
                                                DateTime.Now.Subtract(TimeSpan.FromDays(minAge * 365.25)),
                                                photoReq,
                                                radBox.BottomLine,
                                                radBox.TopLine,
                                                radBox.LeftLine,
                                                radBox.RightLine,
                                                inLocation.Longitude,
                                                inLocation.Latitude,
                                                radBox.Radius,
                                                maxResults);

                    var lResults = new List<string>();

                    while (reader.Read())
                    {
                        var username = (string)reader["Username"];

                        //if (reader["Longitude"] is double && reader["Latitude"] is double)
                        //{
                        //    Location loc = new Location();

                        //    double distance = Distance.GetDistance(inLocation, loc);
                        //    if (distance <= radBox.Radius)
                        lResults.Add(username);
                        //}
                    }

                    return lResults.ToArray();
                }
            }
예제 #6
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;
        }
예제 #7
0
        public static int GetPhotoIdByGender(User.eGender gender)
        {
            int photoId;

            switch (gender)
            {
                case User.eGender.Male:
                    photoId = -1;
                    break;
                case User.eGender.Female:
                    photoId = -2;
                    break;
                case User.eGender.Couple:
                    photoId = -3;
                    break;
                default:
                    photoId = 0;
                    break;
            }

            return photoId;
        }
예제 #8
0
 public static bool IsEventsSettingEnabled(eType type, User user)
 {
     return (user.EventsSettings & (ulong)type) == (ulong)type;
 }
예제 #9
0
        private static ScheduledAnnouncement[] Fetch(int? id, User.eGender? gender, bool? paidMember, bool? hasPhotos,
                                                        bool? hasProfile, int? languageID, string country, string region,
                                                        eType? type)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader = (SqlDataReader) SqlHelper.GetDB().ExecuteReader( "FetchScheduledAnnouncement",
                                                                        id, gender, paidMember, hasPhotos,
                                                                        hasProfile, languageID, country, region, type);

                List<ScheduledAnnouncement> lScheduledAnnouncements = new List<ScheduledAnnouncement>();

                while (reader.Read())
                {
                    ScheduledAnnouncement scheduledAnnouncement = new ScheduledAnnouncement();

                    scheduledAnnouncement.id = (int)reader["ID"];
                    scheduledAnnouncement.name = (string) reader["Name"];
                    scheduledAnnouncement.subject = (string)reader["Subject"];
                    scheduledAnnouncement.body = (string)reader["Body"];
                    scheduledAnnouncement.gender = reader["Gender"] != DBNull.Value
                                                       ? (User.eGender?) ((int) reader["Gender"])
                                                       : null;
                    scheduledAnnouncement.paidMember = reader["PaidMember"] != DBNull.Value
                                                           ? (bool?) reader["PaidMember"]
                                                           : null;
                    scheduledAnnouncement.hasPhotos = reader["HasPhotos"] != DBNull.Value
                                                           ? (bool?)reader["HasPhotos"]
                                                           : null;
                    scheduledAnnouncement.hasProfile = reader["HasProfile"] != DBNull.Value
                                                           ? (bool?)reader["HasProfile"]
                                                           : null;
                    scheduledAnnouncement.languageID = reader["LanguageID"] != DBNull.Value
                                                           ? (int?)reader["LanguageID"]
                                                           : null;
                    scheduledAnnouncement.country = reader["Country"] != DBNull.Value
                                                           ? (string)reader["Country"]
                                                           : null;
                    scheduledAnnouncement.region = reader["Region"] != DBNull.Value
                                                           ? (string)reader["Region"]
                                                           : null;
                    scheduledAnnouncement.type = (eType) reader["Type"];
                    scheduledAnnouncement.date = reader["Date"] != DBNull.Value
                                                           ? (DateTime?)reader["Date"]
                                                           : null;
                    scheduledAnnouncement.days = reader["Days"] != DBNull.Value
                                                           ? (int?)reader["Days"]
                                                           : null;

                    lScheduledAnnouncements.Add(scheduledAnnouncement);
                }

                return lScheduledAnnouncements.ToArray();
            }
        }