Ejemplo n.º 1
0
 public async Task <bool> RegisterCoach(CoachSignUp coachSignUp)
 {
     using (var context = new LearningFivesEntities())
     {
         context.CoachSignUps.Add(coachSignUp);
         return(await context.SaveChangesAsync() > 0);
     }
 }
Ejemplo n.º 2
0
 public async Task <bool> RegisterStudent(StudentSignUp studentSignUp)
 {
     using (var context = new LearningFivesEntities())
     {
         context.StudentSignUps.Add(studentSignUp);
         return(await context.SaveChangesAsync() > 0);
     }
 }
Ejemplo n.º 3
0
        public void UpdateRiotApiSummoner(string summonerName, string server)
        {
            using (var context = new LearningFivesEntities())
            {
                var summonerInfo = context.SummonerInfoes.First(summoner => summoner.SummonerName == summonerName && summoner.ServerName == server);
                if (summonerInfo == null)
                {
                    return;
                }

                var riotApiServer   = RiotApiServers.GetRegionByName(server);
                var riotApiSummoner = RiotApi.GetSummonerByName(summonerName, riotApiServer);
                var riotApiLeague   = RiotApi.GetLeagueEntriesBySummonerId(riotApiSummoner.Id, riotApiServer);

                var newLeagues = new List <RiotAPILeague>();
                foreach (var league in riotApiLeague)
                {
                    var leagueEntry = league.Entries.First();

                    newLeagues.Add(new RiotAPILeague
                    {
                        LeagueName           = league.Name,
                        QueueType            = league.Queue,
                        Tier                 = league.Tier.ToString(),
                        RiotAPILeagueEntries = new List <RiotAPILeagueEntry>
                        {
                            new RiotAPILeagueEntry
                            {
                                Division     = leagueEntry.Rank,
                                IsFreshBlood = leagueEntry.IsFreshBlood,
                                IsHotStreak  = leagueEntry.IsHotStreak,
                                IsInactive   = leagueEntry.IsInactive,
                                IsVeteran    = leagueEntry.IsVeteran,
                                LeaguePoints = leagueEntry.LeaguePoints,
                                Losses       = leagueEntry.Losses,
                                Wins         = leagueEntry.Wins
                            }
                        }
                    });
                }

                summonerInfo.RiotAPISummoners.Clear();
                summonerInfo.RiotAPISummoners.Add(new RiotAPISummoner
                {
                    RiotAPISummonerID = riotApiSummoner.Id,
                    ProfileIconID     = riotApiSummoner.ProfileIconId,
                    RevisionDate      = riotApiSummoner.RevisionDate,
                    SummonerLevel     = riotApiSummoner.SummonerLevel,
                    RiotAPILeagues    = newLeagues
                });

                context.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public async Task <CoachPlayer> RemoveStudentFromCoachAsync(int coachSignUpId, int studentSignUpId)
        {
            using (var context = new LearningFivesEntities())
            {
                var coachPlayer = context.CoachPlayers.FirstOrDefault(i => i.CoachSignUpID == coachSignUpId && i.StudentSignUpID == studentSignUpId);
                if (coachPlayer == null)
                {
                    return(null);
                }

                var result = context.CoachPlayers.Remove(coachPlayer);
                await context.SaveChangesAsync();

                return(result);
            }
        }
Ejemplo n.º 5
0
        public SummonerInfo GetSummonerByName(string summonerName, string server)
        {
            using (var context = new LearningFivesEntities())
            {
                var summonerInfo = context.SummonerInfoes.First(summoner => summoner.SummonerName == summonerName && summoner.ServerName == server);
                if (summonerInfo == null)
                {
                    return(null);
                }

                if (summonerInfo.RiotAPISummoners.Count < 1)
                {
                    UpdateRiotApiSummoner(summonerName, server);
                    summonerInfo = context.SummonerInfoes.First(summoner => summoner.SummonerName == summonerName && summoner.ServerName == server);
                }

                return(summonerInfo);
            }
        }
Ejemplo n.º 6
0
        public async Task <CoachPlayer> AddStudentToCoachAsync(int coachSignUpId, int studentSignUpId)
        {
            using (var context = new LearningFivesEntities())
            {
                var teamSize = await context.CoachPlayers.Where(i => i.CoachSignUpID == coachSignUpId).CountAsync();

                if (teamSize >= TeamSizeLimit)
                {
                    return(null);
                }

                var coachPlayer = context.CoachPlayers.Add(new CoachPlayer
                {
                    CoachSignUp   = context.CoachSignUps.FirstOrDefault(i => i.CoachSignUpID == coachSignUpId),
                    StudentSignUp = context.StudentSignUps.FirstOrDefault(i => i.StudentSignUpID == studentSignUpId)
                });

                await context.SaveChangesAsync();

                return(coachPlayer);
            }
        }
Ejemplo n.º 7
0
        public async Task <List <StudentSignUp> > GetAllStudentsAsync(StudentFilterDM studentFilter)
        {
            using (var context = new LearningFivesEntities())
            {
                context.Configuration.LazyLoadingEnabled = false;
                context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

                var filter = context.StudentSignUps
                             .AsNoTracking()
                             .AsQueryable()
                             .Include(i => i.Commitment)
                             .Include(i => i.RoleInfo)
                             .Include(i => i.SummonerInfo)
                             .Include(i => i.SummonerInfo.RiotAPISummoners.Select(j => j.RiotAPILeagues))
                             .Include(i => i.Toxic);

                if (studentFilter.StudentStatus >= 0)
                {
                    filter = filter.Where(i => i.StudentStatus == studentFilter.StudentStatus);
                }

                if (!string.IsNullOrEmpty(studentFilter.Server))
                {
                    filter = filter.Where(i => i.SummonerInfo.ServerName == studentFilter.Server);
                }

                if (!string.IsNullOrEmpty(studentFilter.RankTier))
                {
                    filter = filter.Where(i => i.SummonerInfo.RiotAPISummoners.Count > 0);

                    filter = filter.Where(i => i.SummonerInfo.RiotAPISummoners
                                          .Any(j => j.RiotAPILeagues
                                               .Any(k => k.QueueType.Equals("RANKED_SOLO_5x5") && k.Tier == studentFilter.RankTier)));
                }

                return(await filter.OrderBy(i => i.SummonerInfo.SummonerName).ToListAsync());
            }
        }