Exemplo n.º 1
0
        public async Task <IHttpActionResult> GetActiveMatches(string opponentId = null, string userID = null)
        {
            string appUserID = (userID == null) ? User.Identity.GetUserId() : userID;

            try
            {
                List <Match> activeMatches = null;
                if (string.IsNullOrWhiteSpace(opponentId))
                {
                    activeMatches = await _matchesService.GetActiveMatchesForId(appUserID);
                }
                else
                {
                    activeMatches = await _matchesService.GetActiveMatchesForIdAndOpponentId(appUserID, opponentId);
                }

                var matchesModels = _mapperToMatchModel.Map <List <MatchViewModel> >(activeMatches);
                return(Ok <List <MatchViewModel> >(matchesModels));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }