Example #1
0
        public static Expression <Func <SportsLinkDB, TennisUserModel, IQueryable <OfferModel> > > GetOffersFunc()
        {
            if (null == OffersQuery)
            {
                var tennisUsers = ModelUtils.GetTennisUsersFunc();

                OffersQuery =
                    (SportsLinkDB db, TennisUserModel user) =>
                    from o in db.Offer
                    join u1 in tennisUsers.Invoke(db) on o.FacebookId equals u1.FacebookId
                    join u2 in tennisUsers.Invoke(db) on o.AcceptedById equals u2.FacebookId
                    into tempUser
                    join accept in db.Accept on o.OfferId equals accept.OfferId
                    into acceptedUsers
                    from confirmedUser in tempUser.DefaultIfEmpty()
                    join u3 in tennisUsers.Invoke(db) on o.SpecificOpponentId equals u3.FacebookId
                    into tempSpecUser
                    from specificUser in tempSpecUser.DefaultIfEmpty()
                    join c in db.City on o.PreferredLocationId equals c.LocationId
                    into tempCity
                    from city in tempCity.DefaultIfEmpty()
                    join ct in db.Court on o.PreferredCourtId equals ct.CourtId
                    into tempCourt
                    from court in tempCourt.DefaultIfEmpty()

                    where
                    user.Gender == u1.Gender && u1.CurrentAvailability &&
                    !acceptedUsers.Any(au => !au.Accepted && au.FacebookId == user.FacebookId)

                    select new OfferModel()
                {
                    OfferId          = o.OfferId,
                    PostDateUtc      = o.PostDateUtc,
                    MatchDateUtc     = o.MatchDateUtc,
                    Court            = court,
                    City             = city,
                    Completed        = o.Completed,
                    Score            = o.Score,
                    Message          = o.Message,
                    RequestComments  = o.RequestComments,
                    AcceptComments   = o.AcceptComments,
                    RequestUser      = u1,
                    ConfirmedUser    = confirmedUser,
                    AcceptedUsers    = acceptedUsers,
                    SpecificOpponent = specificUser,
                    UserPending      = db.Accept.Any(a => a.FacebookId == user.FacebookId && a.OfferId == o.OfferId)
                };
            }

            return(OffersQuery);
        }
Example #2
0
        public PlayersModel(TennisUserModel tennisUserP, SportsLinkDB dbP)
            : base(tennisUserP)
        {
            if (null == CachedQuery)
            {
                var tennisUsers = ModelUtils.GetTennisUsersFunc();
                Expression <Func <SportsLinkDB, TennisUserModel, IQueryable <TennisUserModel> > > players =
                    (SportsLinkDB db, TennisUserModel tennisUser) => tennisUsers.Invoke(db).Where
                        (p =>
                        Math.Abs(p.Rating - tennisUser.Rating) <= 0.25 &&
                        db.CoordinateDistanceMiles(p.City.Latitude, p.City.Longitude, tennisUser.City.Latitude, tennisUser.City.Longitude) < 15 &&
                        p.FacebookId != tennisUser.FacebookId &&
                        p.Gender == tennisUser.Gender
                        );

                CachedQuery = CompiledQuery.Compile <SportsLinkDB, TennisUserModel, IQueryable <TennisUserModel> >
                              (
                    players.Expand()
                              );
            }

            this.Players = CachedQuery(dbP, tennisUserP);
        }