Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Service Method to upsert matches
        /// </summary>
        /// <param name="matches">Domain matches as list</param>
        /// <returns>Task Complete</returns>
        public async Task UpsertMatches(List <Match> matches, string token)
        {
            //validate matches list is not null or empty
            if (matches == null || matches.Count <= 0)
            {
                throw new ArgumentException();
            }

            //validate token is not empty
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentException();
            }

            //create new list of db matches
            var dbMatches = new List <Matches>();

            //validate matches
            var validatedMatches = await UpsertValidation(matches, token);

            if (validatedMatches.Count <= 0)
            {
                throw new Exception();
            }
            //map domain matches to db matches
            foreach (var match in validatedMatches)
            {
                dbMatches.Add(AdoMatchesMapper.CoreModelToDbEntity(match));
            }

            //call method
            await _matchesRepository.UpsertMatches(dbMatches);
        }
Exemplo n.º 3
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);
        }