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);
        }
Esempio n. 2
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);
        }