コード例 #1
0
        public IEnumerable<Match> GetMatchesAsync(string userid, string city, string minAge, string maxAge)
        {
            int minAgeInt = Convert.ToInt32(minAge);
            int maxAgeInt = Convert.ToInt32(maxAge);
            if (minAgeInt == 0) minAgeInt = 18;
            if (maxAgeInt == 0) maxAgeInt = 100;

            User user = auth.Authorize(WebOperationContext.Current.IncomingRequest);
            if (user.Id != Convert.ToInt32(userid)) throw new WebFaultException(System.Net.HttpStatusCode.Unauthorized);

            var guides = userDA.GetAll()
                .Where(
                u => u.Id != user.Id
                && u.City != null
                && u.City.Name.ToLower() == city.ToLower()
                && u.Age >= minAgeInt
                && u.Age <= maxAgeInt)
                .ToList();
            var matches = new Match[guides.Count];

            Parallel.For(0, guides.Count, index =>
            {
                matches[index] = provider.GetMatch(user, guides[index]);
            });

            var matchList = matches.OrderByDescending(m => m.Score).ToList();
            return matchList;
        }
コード例 #2
0
 public Match GetMatch(User traveler, User guide)
 {
     var match = new Match()
     {
         Traveler = traveler,
         Guide = guide,
         Score = CalculateScore(traveler, guide)
     };
     return match;
 }