Exemplo n.º 1
0
        public async Task <Result> FollowLeague(League league, FantasyCriticUser user)
        {
            if (!league.PublicLeague)
            {
                return(Result.Failure("League is not public"));
            }

            bool userIsInLeague = await _leagueMemberService.UserIsInLeague(league, user);

            if (userIsInLeague)
            {
                return(Result.Failure("Can't follow a league you are in."));
            }

            var followedLeagues = await GetFollowedLeagues(user);

            bool userIsFollowingLeague = followedLeagues.Any(x => x.LeagueID == league.LeagueID);

            if (userIsFollowingLeague)
            {
                return(Result.Failure("User is already following that league."));
            }

            await _fantasyCriticRepo.FollowLeague(league, user);

            return(Result.Success());
        }