コード例 #1
0
        public AcceptPlayersDataGridModel(Guid offerGuid, TennisUserModel tennisUser, SportsLinkDB db)
            : base(null, tennisUser, db)
        {
            // No need for a header
            this.ShowHeader = true;

            // Get list of users who have accepted the offer
            IQueryable <Accept> accepts = db.Accept.Where(a => a.OfferId == offerGuid);

            IQueryable <TennisUserModel> tennisUsers = ModelUtils.GetTennisUsers(db);

            var acceptUsers = from a in accepts
                              join tu in tennisUsers
                              on a.FacebookId equals tu.FacebookId
                              where a.Accepted
                              select tu;


            this.Data = acceptUsers;
            this.Rows = acceptUsers;

            this.AddColumn("FacebookId", "", "PlayerGrid/UserPicture", null);
            this.AddColumn("Name", "Name");
            this.AddColumn("Rating", "Rating", (o) => IndexModel.FormatRating((double)o));
            this.AddColumn("Birthday", "Age", (o) => IndexModel.FormatAge((DateTime)o));
            this.AddColumn("City.Name", "Location");
            this.AddColumn("FacebookId", "Select Opponent", "PlayerGrid/UserSelect", null);
        }
コード例 #2
0
        public PotentialOffersModel(TennisUserModel tennisUserP, SportsLinkDB dbP)
            : base(tennisUserP)
        {
            // BUGBUG: get rid of the hard-coded values
            if (null == CachedQuery)
            {
                var offers = ModelUtils.GetOffersFunc();

                Expression <Func <SportsLinkDB, TennisUserModel, IQueryable <OfferModel> > > results =
                    (SportsLinkDB db, TennisUserModel tennisUser) =>
                    offers.Invoke(db, tennisUser)
                    .Where
                        (o =>
                        o.ConfirmedUser == null &&
                        (o.SpecificOpponent == null || o.SpecificOpponent.FacebookId == tennisUser.FacebookId) &&
                        o.RequestUser.FacebookId != tennisUser.FacebookId &&
                        o.MatchDateUtc >= DateTime.UtcNow &&
                        Math.Abs(tennisUser.Rating - o.RequestUser.Rating) <= 0.25 &&
                        db.CoordinateDistanceMiles(o.City.Latitude, o.City.Longitude, tennisUser.City.Latitude, tennisUser.City.Longitude) < 15
                        ).OrderBy(o => Math.Abs(tennisUser.Rating - o.RequestUser.Rating)).Take(20);

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

            this.PotentialOffers = CachedQuery(dbP, tennisUserP);
        }
コード例 #3
0
        public ConfirmedMatchesModel(TennisUserModel tennisUserP, SportsLinkDB dbP)
            : base(tennisUserP)
        {
            // Select confirmed matchs which do not have a score yet where the current user is either a requestor or an acceptor
            // BUGBUG: we might want to eliminate confirmed matches that way older than current time (user might have forgotten to enter a score)
            if (null == CachedQuery)
            {
                var offers = ModelUtils.GetOffersFunc();

                Expression <Func <SportsLinkDB, TennisUserModel, IQueryable <OfferModel> > > results =
                    (SportsLinkDB db, TennisUserModel tennisUser) =>
                    offers.Invoke(db, tennisUser)
                    .Where(o => o.ConfirmedUser != null)
                    .Where(o => (o.ConfirmedUser.FacebookId == tennisUser.FacebookId || o.RequestUser.FacebookId == tennisUser.FacebookId))
                    .Where(o => (o.Score == null || o.Score == ""))
                    .OrderByDescending(o => o.MatchDateUtc);

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

            this.ConfirmedMatches = CachedQuery(dbP, tennisUserP);
        }
コード例 #4
0
        public CalendarModel(DateTime startDateP, TennisUserModel tennisUserP, SportsLinkDB dbP)
            : base(tennisUserP)
        {
            this.UserStartDate = IndexModel.GetLocalDate(startDateP.ToUniversalTime(), tennisUserP.TimeZoneOffset);
            this.UserStartDate = this.UserStartDate.AddDays(-(int)this.UserStartDate.DayOfWeek);
            this.StartDate     = IndexModel.GetUtcDate(this.UserStartDate, tennisUserP.TimeZoneOffset);
            this.EndDate       = this.StartDate.AddDays(7);

            if (null == CachedQuery)
            {
                var offers = ModelUtils.GetOffersFunc();

                Expression <Func <SportsLinkDB, TennisUserModel, DateTime, DateTime, IQueryable <OfferModel> > > results =
                    (SportsLinkDB db, TennisUserModel tennisUser, DateTime startDate, DateTime endDate) =>
                    offers.Invoke(db, tennisUser)
                    .Where(o => o.RequestUser.FacebookId != tennisUser.FacebookId)
                    .Where(o => o.SpecificOpponent == null || o.SpecificOpponent.FacebookId == tennisUser.FacebookId || o.RequestUser.FacebookId == tennisUser.FacebookId)
                    .Where(o => o.ConfirmedUser == null || o.ConfirmedUser.FacebookId == tennisUser.FacebookId || o.RequestUser.FacebookId == tennisUser.FacebookId)
                    .Where(o => o.MatchDateUtc >= startDate)
                    .Where(o => o.MatchDateUtc < endDate)
                    .Where(o => o.MatchDateUtc >= DateTime.UtcNow || null != o.ConfirmedUser)
                    .OrderBy(o => o.MatchDateUtc);

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

            this.Offers = CachedQuery(dbP, tennisUserP, this.StartDate, this.EndDate);
        }
コード例 #5
0
        /// <summary>
        /// Gets all offers for the matching gender of the user passed in
        /// - also for each offer selected, sets a flag whether the user passed in has accepted the offer
        /// - only selects offers for which the offerer is available
        /// </summary>
        /// <param name="db"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public static IQueryable <OfferModel> GetOffers(SportsLinkDB db, TennisUserModel user)
        {
            var tennisUsers = ModelUtils.GetTennisUsers(db);

            IQueryable <OfferModel> offers = from o in db.Offer
                                             join u1 in tennisUsers on o.FacebookId equals u1.FacebookId
                                             join u2 in tennisUsers 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 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(offers);
        }
コード例 #6
0
        public DataGridModel(string filters, TennisUserModel tennisUser, SportsLinkDB db)
            : base(tennisUser)
        {
            this.Columns      = new List <ColumnDefinition>();
            this.FilterValues = new Dictionary <string, List <string> >();

            if (!string.IsNullOrEmpty(filters))
            {
                foreach (string filter in filters.Split(new string[] { ",," }, StringSplitOptions.RemoveEmptyEntries))
                {
                    string[] filterPieces = filter.Split('=');
                    string   filterName   = filterPieces[0];
                    string[] filterValues = filterPieces[1].Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries);

                    this.FilterValues.Add(filterName, new List <string>(filterValues));
                }
            }
        }
コード例 #7
0
ファイル: PlayersModel.cs プロジェクト: nbclark/SportsLink
        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);
        }
コード例 #8
0
        public UserOffersModel(TennisUserModel tennisUserP, SportsLinkDB dbP)
            : base(tennisUserP)
        {
            // BUGBUG: what about offers which were not confirmed and where the offer time is past - we need to eliminate those from the db
            if (null == CachedQuery)
            {
                var offers = ModelUtils.GetOffersFunc();

                Expression <Func <SportsLinkDB, TennisUserModel, IQueryable <OfferModel> > > results =
                    (SportsLinkDB db, TennisUserModel tennisUser) =>
                    offers.Invoke(db, tennisUser)
                    .Where(o => o.ConfirmedUser == null)
                    .Where(o => o.RequestUser.FacebookId == tennisUser.FacebookId && o.MatchDateUtc > DateTime.UtcNow)
                    .OrderBy(o => o.MatchDateUtc);

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

            this.UserOffers = CachedQuery(dbP, tennisUserP);
        }
コード例 #9
0
ファイル: ResultsModel.cs プロジェクト: nbclark/SportsLink
        public ResultsModel(TennisUserModel tennisUserP, SportsLinkDB dbP)
            : base(tennisUserP)
        {
            if (null == CachedQuery)
            {
                var offers = ModelUtils.GetOffersFunc();

                Expression <Func <SportsLinkDB, TennisUserModel, IQueryable <OfferModel> > > results =
                    (SportsLinkDB db, TennisUserModel tennisUser) =>
                    offers.Invoke(db, tennisUser)
                    .Where(o => o.ConfirmedUser != null)
                    .Where(o => (o.ConfirmedUser.FacebookId == tennisUser.FacebookId || o.RequestUser.FacebookId == tennisUser.FacebookId))
                    .Where(o => (o.Score != null && o.Score != ""))
                    .OrderByDescending(o => o.MatchDateUtc);

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

            this.UserResults = CachedQuery(dbP, tennisUserP);
        }
コード例 #10
0
        public PlayersDataGridModel(string filter, TennisUserModel tennisUser, SportsLinkDB db)
            : base(filter, tennisUser, db)
        {
            this.ShowHeader = true;
            var tennisUsers = ModelUtils.GetTennisUsers(db);

            this.Data = tennisUsers
                        .Where(p => p.FacebookId != tennisUser.FacebookId && db.CoordinateDistanceMiles(p.City.Latitude, p.City.Longitude, tennisUser.City.Latitude, tennisUser.City.Longitude) < 15)
                        .OrderByDescending(p => db.CoordinateDistanceMiles(p.City.Latitude, p.City.Longitude, tennisUser.City.Latitude, tennisUser.City.Longitude));

            var rows = this.Data.Where
                       (
                p =>
                /*Math.Abs(p.Rating - tennisUser.Rating) <= 0.25 &&*/
                p.Gender == tennisUser.Gender
                       );

            if (!this.FilterValues.ContainsKey("Rating"))
            {
                List <string> ratings = new List <string>();

                for (double rating = this.TennisUser.Rating - 0.25; rating <= this.TennisUser.Rating + 0.25; rating += 0.25)
                {
                    ratings.Add(IndexModel.RatingToString(rating));
                }

                this.FilterValues.Add("Rating", ratings);
            }

            foreach (string filterName in this.FilterValues.Keys)
            {
                List <string> values = this.FilterValues[filterName];

                switch (filterName)
                {
                case "Rating":
                {
                    rows = rows.Where(u => values.Select(r => double.Parse(r)).Contains(u.Rating));
                }
                break;

                case "Birthday":
                {
                    rows = rows.Where(u => values.Contains(((u.Age / 5) * 5).ToString()));
                }
                break;

                case "City.Name":
                {
                    rows = rows.Where(u => values.Contains(u.City.LocationId.ToString()));
                }
                break;
                }
            }

            this.Rows = rows;

            this.AddColumn("FacebookId", "", "PlayerGrid/UserPicture", null);
            this.AddColumn("Name", "Name");
            this.AddColumn("Rating", "Rating", (o) => IndexModel.FormatRating((double)o)).CanFilter = true;
            this.AddColumn("Birthday", "Age", (o) => IndexModel.FormatAge((DateTime)o)).CanFilter   = true;
            this.AddColumn("City.Name", "Location").CanFilter = true;
            this.AddColumn("FacebookId", "Challenge", "PlayerGrid/UserChallenge", null);
        }
コード例 #11
0
 public ModuleModel(TennisUserModel tennisUser, SportsLinkDB db)
     : this(tennisUser)
 {
 }
コード例 #12
0
 public ModuleModel(TennisUserModel tennisUser)
 {
     this.TennisUser = tennisUser;
 }
コード例 #13
0
 public static T GetModel <T>(TennisUserModel tennisUser, SportsLinkDB db)
 {
     return((T)Activator.CreateInstance(typeof(T), tennisUser, db));
 }
コード例 #14
0
 public IndexModel(TennisUserModel tennisUser, SportsLinkDB db)
     : base(tennisUser)
 {
     this.DB = db;
 }