Esempio n. 1
0
        public IActionResult GetForUser()
        {
            var userName = HttpContext.User.Identity.Name;

            // Create all tips for the user if it's his first login.
            var matches = _matchesRepository.GetAllMatches();

            if (!matches.All(x => x.Tips != null && x.Tips.Any(y => y.User.Equals(userName))))
            {
                var tips = new List <Tip>();
                foreach (var match in matches.Where(x => x.Tips == null || !x.Tips.Any(y => y.User.Equals(userName))))
                {
                    tips.Add(new Tip {
                        User = userName, MatchId = match.Id
                    });
                }

                _tipsRepository.AddTips(tips);
                matches = _matchesRepository.GetAllMatches();
            }

            var matchModels = MapMatches(matches, userName);

            return(Ok(matchModels));
        }
 public async Task <IEnumerable <Match> > GetAllMatches()
 {
     return(await _matchesRepository.GetAllMatches());
 }