Esempio n. 1
0
        public object Get(GetMatchesRequest Request)
        {
            User user = GetAuthenticatedUser(((NHibernate.ISession)base.Request.Items["hibernateSession"]));

            IQueryable <Match> Matches = new BaseRepository <Match>(((NHibernate.ISession)base.Request.Items["hibernateSession"])).List(x =>
                                                                                                                                        x.SecondUser != null
                                                                                                                                        &&
                                                                                                                                        (x.FirstUser == user || x.SecondUser == user)
                                                                                                                                        &&
                                                                                                                                        (x.IsFirstUserLike && x.IsSecondUserLike != null && x.IsSecondUserLike == true)
                                                                                                                                        ).OrderByDescending(y => y.Updated);

            GetMatchesResponse Response = new GetMatchesResponse(user, Matches.ToList());

            Response.data = Response.data.Skip(Request.offset).ToArray();

            if (Request.limit > 0)
            {
                Response.data = Response.data.Take(Request.limit).ToArray();
            }

            return(Response);
        }
Esempio n. 2
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetMatchesResponse response = new GetMatchesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Matches", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <MatchItem, MatchItemUnmarshaller>(MatchItemUnmarshaller.Instance);
                    response.Matches = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("MatchGenerationDate", targetDepth))
                {
                    var unmarshaller = DateTimeUnmarshaller.Instance;
                    response.MatchGenerationDate = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("PotentialMatches", targetDepth))
                {
                    var unmarshaller = IntUnmarshaller.Instance;
                    response.PotentialMatches = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        private async Task SyncTeamMatches(int?teamId, int frenoyDivisionId, GetMatchesResponse matches, int?frenoySeason = null)
        {
            frenoySeason = frenoySeason ?? _db.CurrentFrenoySeason;

            foreach (TeamMatchEntryType frenoyMatch in matches.TeamMatchesEntries)
            {
                // Kalender entries
                MatchEntity matchEntity = await _db.Matches.SingleOrDefaultAsync(x => x.FrenoyMatchId == frenoyMatch.MatchId && x.FrenoySeason == frenoySeason.Value);

                if (matchEntity == null)
                {
                    matchEntity = new MatchEntity();
                    await MapMatch(matchEntity, teamId, frenoyDivisionId, frenoyMatch, frenoySeason.Value);

                    _db.Matches.Add(matchEntity);
                    await CommitChanges();
                }
                else
                {
                    await MapMatch(matchEntity, teamId, frenoyDivisionId, frenoyMatch, frenoySeason);
                    await CommitChanges();
                }
            }
        }
        private void SyncMatches(int? teamId, int frenoyDivisionId, GetMatchesResponse matches, bool alsoSyncMatchDetails = true, int frenoySeason = Constants.FrenoySeason)
        {
            foreach (TeamMatchEntryType frenoyMatch in matches.TeamMatchesEntries.Where(x => !x.HomeTeam.Trim().StartsWith("Vrij") && !x.AwayTeam.Trim().StartsWith("Vrij")))
            {
                Debug.Assert(frenoyMatch.DateSpecified, "Probably need to filter this one out?");
                Debug.Assert(frenoyMatch.TimeSpecified);

                // Kalender entries
                MatchEntity matchEntity = _db.Matches.SingleOrDefault(x => x.FrenoyMatchId == frenoyMatch.MatchId && x.FrenoySeason == frenoySeason);
                if (matchEntity == null)
                {
                    matchEntity = new MatchEntity();
                    MapMatch(matchEntity, teamId, frenoyDivisionId, frenoyMatch, frenoySeason);
                    _db.Matches.Add(matchEntity);
                    CommitChanges();
                }
                else
                {
                    MapMatch(matchEntity, teamId, frenoyDivisionId, frenoyMatch, frenoySeason);
                    CommitChanges();
                }

                if (alsoSyncMatchDetails)
                {
                    SyncMatchDetails(matchEntity, frenoyMatch);
                }
            }
        }