Example #1
0
        /// <summary>
        /// Service method to pull matches by user id
        /// </summary>
        /// <param name="userId">User ID as long</param>
        /// <returns>List of domain matches</returns>

        public async Task <List <Match> > GetMatchesByUserId(long userId, string token)
        {
            //validate input
            if (userId <= 0)
            {
                throw new ArgumentException();
            }

            var dbMatches = await _matchesRepository.GetMatchesByUserId(userId);

            //validate db matches are not empty
            if (dbMatches == null || dbMatches.Count <= 0)
            {
                throw new Exception();
            }

            //create new list of domain matches
            List <Match> domainMatches = new List <Match>();

            //map db matches to domain matches
            foreach (var dbMatch in dbMatches)
            {
                if (dbMatch.Matched != false || dbMatch.Matched == null)
                {
                    domainMatches.Add(AdoMatchesMapper.DbEntityToCoreModel(dbMatch));
                }
                continue;
            }

            return(domainMatches);
        }
Example #2
0
        /// <summary>
        /// Service method to pull single match by match id
        /// </summary>
        /// <param name="matchId">Long</param>
        /// <returns>Domain match model</returns>
        public async Task <Match> GetMatchByMatchId(long matchId, string token)
        {
            //validate input
            if (matchId <= 0)
            {
                throw new ArgumentException();
            }

            //pull match from db
            var dbMatch = await _matchesRepository.GetMatchByMatchId(matchId);

            //validate db match is not empty
            if (dbMatch == null)
            {
                throw new Exception();
            }

            //map db match to domain match
            var domainMatch = AdoMatchesMapper.DbEntityToCoreModel(dbMatch);

            //return domain match
            return(domainMatch);
        }