示例#1
0
        public ILeague GetGenericLeague()
        {
            ILeague league = null;

            string leagueName = "Quick Play";

            using (var context = new Data.DartballContext()) {
                var item = context.Leagues.FirstOrDefault(x => x.Name == leagueName);
                if (item == null)
                {
                    LeagueDto dto = new LeagueDto()
                    {
                        Name     = leagueName,
                        Password = "******"
                    };
                    AddNew(dto);

                    item   = context.Leagues.FirstOrDefault(x => x.Name == leagueName);
                    league = Mapper.Map <LeagueDto>(item);
                }
                else
                {
                    league = Mapper.Map <LeagueDto>(item);
                }
            }

            return(league);
        }
        public void Execute(LeagueDto request)
        {
            if (Context.Leagues.Any(l => l.Name == request.Name))
            {
                throw new EntityAlreadyExistsException("league");
            }

            List <RefereeLeague> lista = new List <RefereeLeague>();

            if (request.RefereesId != null)
            {
                foreach (var refereeId in request.RefereesId)
                {
                    if (!Context.Referees.Any(l => l.Id == refereeId))
                    {
                        throw new EntityNotFoundException("Referee");
                    }

                    lista.Add(new RefereeLeague {
                        LeagueId = request.Id, RefereeId = refereeId
                    });
                }
            }

            Context.Leagues.Add(new League {
                LeagueReferees = lista,

                Level     = request.Level,
                IsDeleted = false,
                Name      = request.Name
            });
            Context.SaveChanges();
        }
示例#3
0
        public bool ExistsInDb(LeagueDto league)
        {
            Connection.BeginTransaction();

            var rows = Connection.Query <int>(@"SELECT COUNT(1) as 'Count' FROM League WHERE LeagueId = @LeagueId", new { LeagueId = league.LeagueId });

            Connection.Commit();

            return(rows.First() > 0);
        }
示例#4
0
        private LeagueDto GetLeague(int leagueId)
        {
            var leagueDto = db.Leagues.Select(a => LeagueDto.Create(a)).FirstOrDefault(a => a.Id == leagueId);

            if (leagueDto == null)
            {
                throw new Exception("league doesn't exist");
            }
            return(leagueDto);
        }
示例#5
0
        private void InsertLeague(LeagueDto league)
        {
            string insertQuery = @"INSERT INTO League
                    (LeagueId, Name, Password, DeleteDate)
                    values(@LeagueId, @Name, @Password, @DeleteDate)";

            Connection.BeginTransaction();
            Connection.Execute(insertQuery, league);
            Connection.Commit();
        }
示例#6
0
        public async Task <IActionResult> Save([FromBody] LeagueDto dto)
        {
            if (!this._service.HasAccess(dto))
            {
                return(Forbid());
            }
            await this._service.SaveAsync(dto);

            return(Ok());
        }
        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string      nameSummoner = NavigationContext.QueryString["name"];
            SummonerDto summoner     = new SummonerDto();

            try
            {
                summoner = await summoner.SearchSummoner(nameSummoner);

                textBlockNomeInv.Text = summoner.Nome;
            }
            catch
            {
                MessageBox.Show("Não existe um invocador com esse nome.");
                NavigationService.GoBack();
                return;
            }
            textBlockLevel.Text += summoner.SummonerLevel.ToString();
            try
            {
                LeagueDto leagueSummoner = new LeagueDto();
                leagueSummoner = await leagueSummoner.SearchLeague(summoner.Id);

                textBlockElo.Text = leagueSummoner.Tier + " " + leagueSummoner.Entries[0].Division;
                textBlockVit.Text = leagueSummoner.Entries[0].Wins > 1 ? leagueSummoner.Entries[0].Wins.ToString() + " vitórias" : leagueSummoner.Entries[0].Wins.ToString() + " vitória";
                textBlockDer.Text = leagueSummoner.Entries[0].Losses > 1 ? leagueSummoner.Entries[0].Losses.ToString() + " derrotas" : leagueSummoner.Entries[0].Losses.ToString() + " derrota";
            }
            catch
            {
                MessageBox.Show("Informações de derrotas e vitórias são apenas para jogadores ranqueados.", "Informação", MessageBoxButton.OK);
                textBlockElo.Text = "Unranked";
                textBlockVit.Text = "0 vitória";
                textBlockDer.Text = "0 derrota";
            }
            imageInvocador.Source = await summoner.GetProfileIcon();

            RecentGamesDto gamesRecent         = await new RecentGamesDto().GetLatestGamesById(summoner.Id);
            List <int>     lastChampionsPlayed = new List <int>();

            foreach (GameDto game in gamesRecent.Games)
            {
                lastChampionsPlayed.Add(game.ChampionId);
                LastMatches controlMatch = new LastMatches(game);
                controlMatch.Margin = new Thickness(0, 0, 0, 10);
                controlMatch.Load();
                listboxPartidas.Items.Add(controlMatch);
            }
            int         idChampPref = lastChampionsPlayed[new Random().Next(lastChampionsPlayed.Count - 1)];
            ImageBrush  imgBrush    = new ImageBrush();
            BitmapImage source      = (await ChampionDto.SearchChampionAllData(idChampPref)).GetChampionSplash(0);

            imgBrush.ImageSource  = source;
            imgBrush.Stretch      = Stretch.UniformToFill;
            LayoutRoot.Background = imgBrush;
        }
示例#8
0
 /// <summary>
 /// data layer will determine add vs update
 /// </summary>
 /// <param name="league"></param>
 public void Save(LeagueDto league)
 {
     if (ExistsInDb(league))
     {
         Update(league);
     }
     else
     {
         AddNew(league);
     }
 }
示例#9
0
        private void UpdateLeague(LeagueDto league)
        {
            string updateQuery = @"update League
            set DeleteDate = @DeleteDate,
            Name = @Name,
            Password = @Password
            where LeagueId = @LeagueId";

            Connection.BeginTransaction();
            Connection.Execute(updateQuery, league);
            Connection.Commit();
        }
示例#10
0
        private LeagueDto Map(LeagueModel model)
        {
            if (model == null)
            {
                return(null);
            }
            LeagueDto dto = new LeagueDto();

            dto.caption = model.caption;
            dto.league  = model.league;
            dto.year    = model.year;
            return(dto);
        }
示例#11
0
        private LeagueModel Map(LeagueDto dto)
        {
            if (dto == null)
            {
                return(null);
            }
            LeagueModel model = new LeagueModel();

            model.caption = dto.caption;
            model.league  = dto.league;
            model.year    = dto.year;
            return(model);
        }
示例#12
0
        public void LeagueNameBlankTest()
        {
            LeagueDto dto = new LeagueDto
            {
                LeagueId = TEST_ALTERNATE_ID,
                Name     = string.Empty,
                Password = TEST_LEAGUE_PASSWORD
            };

            var result = LeagueService.AddNew(dto);

            Assert.IsFalse(result.IsSuccess);
        }
示例#13
0
        public void LeagueNameLengthTest()
        {
            LeagueDto dto = new LeagueDto
            {
                LeagueId = TEST_ALTERNATE_ID,
                Name     = TEST_LEAGUE_NAME + "dfaodsfhoas;dhg;oahg;oahego;ha;ldgjh;sadjghadfasdfadfasdgfasdgsadasdgasdgasdgasdg;kasjdhg;kjsahdg;hasdg;jhasdg;jhas;dgkjh;sadkjh;asjhg;kajhgd",
                Password = TEST_LEAGUE_PASSWORD
            };

            var result = LeagueService.AddNew(dto);

            Assert.IsFalse(result.IsSuccess);
        }
        private LeagueDto CreateLeagueDtoWithLinks(League league)
        {
            LeagueDto leagueDto = new LeagueDto
            {
                Name = league.Name
            };

            leagueDto.Links.Add(new Link(
                                    _urlHelper.Link(nameof(GetGames), new { sport = league.Sport.Name, league = league.Name }).ToLower(),
                                    "games",
                                    "GET"));

            return(leagueDto);
        }
示例#15
0
        public Guid SeedLeague()
        {
            Guid id = Guid.NewGuid();

            LeagueDto dto = new LeagueDto()
            {
                LeagueId = id,
                Name     = "Seed League",
                Password = "******"
            };

            League.AddNew(dto);

            return(id);
        }
示例#16
0
        public LeagueDto LoadByKey(Guid leagueId)
        {
            LeagueDto league = null;

            Connection.BeginTransaction();

            var result = Connection.Query <LeagueDto>(
                SELECT_QUERY + " where LeagueId = @LeagueId",
                new { LeagueId = leagueId.ToString() });

            league = result.FirstOrDefault();

            Connection.Commit();

            return(league);
        }
示例#17
0
        public async Task <IActionResult> GetLeague()
        {
            var league = await _repo.GetLeague();

            var leagueState = await _repo.GetLeagueStateForId(league.StateId);

            LeagueDto leagueDto = new LeagueDto
            {
                Id      = league.Id,
                StateId = league.StateId,
                Day     = league.Day,
                State   = leagueState.State,
                Year    = league.Year
            };

            return(Ok(leagueDto));
        }
示例#18
0
        public async Task SaveAsync(LeagueDto leagueDto)
        {
            League league;

            if (leagueDto.Id > 0)
            {
                league = await this.GetSingleLeagueAsync(leagueDto.Id);
            }
            else
            {
                league = new League();
                _context.Leagues.Add(league);
            }

            leagueDto.WrapIn(league, _context);

            await _context.SaveChangesAsync();
        }
示例#19
0
        // POST tables/League
        public async Task <IHttpActionResult> PostLeague(LeagueDto item)
        {
            var exists = _context.Leagues.Any(l => l.Name.Equals(item.Name, System.StringComparison.InvariantCultureIgnoreCase));

            if (exists)
            {
                return(BadRequest("The name of that league is already in use."));
            }

            League league = await InsertAsync(item.ToLeague());

            if (league.IsAcceptingMembers)
            {
                NotifyAboutNewLeagueOpenEnrollment(league);
            }

            return(CreatedAtRoute("Tables", new { id = league.Id }, league));
        }
示例#20
0
        public IActionResult Post([FromBody] LeagueDto leagueDto)
        {
            try
            {
                _addLeagueCommand.Execute(leagueDto);
                return(StatusCode(201));
            }
            catch (EntityNotFoundException e)
            {
                return(NotFound(e.Message));
            }

            catch (EntityAlreadyExistsException e)
            {
                return(Conflict(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
示例#21
0
        public IActionResult Put(int id, [FromBody] LeagueDto leagueDto)
        {
            leagueDto.Id = id;
            try
            {
                _editLeagueCommand.Execute(leagueDto);
                return(NoContent());
            }

            catch (EntityNotFoundException e)
            {
                return(Conflict(e.Message));
            }
            catch (EntityAlreadyExistsException e)
            {
                return(Conflict(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
示例#22
0
        public void AddRemoveLeagueTest()
        {
            LeagueDto dto = new LeagueDto
            {
                LeagueId = TEST_ALTERNATE_ID,
                Name     = TEST_LEAGUE_NAME,
                Password = TEST_LEAGUE_PASSWORD
            };

            var result = LeagueService.AddNew(dto);

            Assert.IsTrue(result.IsSuccess);

            //make sure the league is actually in the db
            var league = LeagueService.GetLeague(TEST_ALTERNATE_ID);

            Assert.IsNotNull(league);
            Assert.AreEqual(TEST_LEAGUE_NAME, league.Name);
            Assert.AreEqual(TEST_LEAGUE_PASSWORD, league.Password);

            //make sure an update works
            dto.Name = TEST_LEAGUE_NAME_2;
            var nameChangeResult = LeagueService.Update(dto);

            Assert.IsTrue(nameChangeResult.IsSuccess);

            league = LeagueService.GetLeague(TEST_ALTERNATE_ID);
            Assert.AreEqual(TEST_LEAGUE_NAME_2, league.Name);

            //cleanup by deleting the record
            var deleteResult = LeagueService.RemoveLeague(TEST_ALTERNATE_ID);

            Assert.IsTrue(deleteResult.IsSuccess);

            //make sure the league is gone
            var deletedLeague = LeagueService.GetLeague(TEST_ALTERNATE_ID);

            Assert.IsNull(deletedLeague);
        }
示例#23
0
        public void Execute(LeagueDto request)
        {
            var league = Context.Leagues.Include(l => l.Clubs).Include(l => l.LeagueReferees).Where(l => l.Id == request.Id && l.IsDeleted == false).FirstOrDefault();

            if (request.Level != 0)
            {
                league.Level = request.Level;
            }
            if (request.Name != null)
            {
                if (league.Name.ToLower() == request.Name.ToLower())
                {
                    throw new EntityAlreadyExistsException("league");
                }
                league.Name = request.Name;
            }

            List <RefereeLeague> lista = new List <RefereeLeague>();

            if (request.RefereesId != null)
            {
                foreach (var refereeId in request.RefereesId)
                {
                    if (!Context.Referees.Any(l => l.Id == refereeId))
                    {
                        throw new EntityNotFoundException("Referee");
                    }

                    lista.Add(new RefereeLeague {
                        LeagueId = request.Id, RefereeId = refereeId
                    });
                }
                league.LeagueReferees = lista;
            }


            Context.SaveChanges();
        }
示例#24
0
 public static League ToLeague(this LeagueDto dto)
 {
     return(new League
     {
         Id = dto.Id,
         Name = dto.Name,
         Description = dto.Description,
         Sport = dto.Sport,
         IsEnabled = dto.IsEnabled,
         StartDate = dto.StartDate,
         EndDate = dto.EndDate,
         UpdatedAt = dto.UpdatedAt,
         Season = dto.Season,
         RulesUrl = dto.RulesUrl,
         MaxChallengeRange = dto.MaxChallengeRange,
         MinHoursBetweenChallenge = dto.MinHoursBetweenChallenge,
         MatchGameCount = dto.MatchGameCount,
         HasStarted = dto.HasStarted,
         ImageUrl = dto.ImageUrl,
         CreatedByAthleteId = dto.CreatedByAthleteId,
         IsAcceptingMembers = dto.IsAcceptingMembers
     });
 }
示例#25
0
        public StatTableDto GetCareerGoalieTable(StatParametersDto paramDto)
        {
            StatTableDto      statTableDto    = new StatTableDto();
            StatParametersDto cleanParameters = CleanCareerParameters(paramDto);

            cleanParameters.Col = cleanParameters.Col ?? 1;

            using (db = new BojoBoxContext())
            {
                LeagueDto  leagueDto = GetLeague(cleanParameters.League.Value);
                TeamDto    teamDto   = GetTeam(cleanParameters.Team.Value);
                List <int> teamIds   = null;
                if (teamDto != null)
                {
                    teamIds = GetFranchiseTeamIds(teamDto.Id);
                }

                statTableDto.Teams = GetTeamParameters(leagueDto.Id);

                statTableDto.HeaderText = leagueDto.Acronym + " - Career Stats";

                var goalieCareerQuery = db.GoalieSeasons.Where(a => a.LeagueId == leagueDto.Id);

                if (teamDto != null)
                {
                    goalieCareerQuery = goalieCareerQuery.Where(a => a.TeamId.HasValue && teamIds.Contains(a.TeamId.Value));
                }
                else
                {
                    goalieCareerQuery = goalieCareerQuery.Where(a => a.TeamId.HasValue);
                }

                bool isPlayoffs = CheckIfPlayoffs(cleanParameters.SeasonType.Value);
                goalieCareerQuery = goalieCareerQuery.Where(a => a.isPlayoffs == isPlayoffs);

                var idStatPairs = GetIdStatPairsCareer(cleanParameters.Col, goalieCareerQuery);
                idStatPairs = idStatPairs.GroupBy(a => a.Id, b => b.Stat, (x, y) => new IdStatPair(x, y.Sum()));

                idStatPairs = idStatPairs.OrderByDescending(a => a.Stat);
                // TODO: Check if to sort ascending

                int pageSize = 20;
                statTableDto.PageCount = GetPageCount(cleanParameters, idStatPairs);
                var selectedGoalieIds = idStatPairs.Select(b => b.Id).Skip(cleanParameters.Page.Value * pageSize).Take(pageSize).ToArray();

                var goalieRows = db.GoalieSeasons
                                 .Include(a => a.Goalie)
                                 .Where(a => selectedGoalieIds.Contains(a.GoalieId))
                                 .Where(a => a.TeamId.HasValue)
                                 .Where(a => a.LeagueId == leagueDto.Id)
                                 .Where(a => a.isPlayoffs == isPlayoffs);

                if (teamDto != null)
                {
                    goalieRows = goalieRows.Where(a => a.TeamId.HasValue && teamIds.Contains(a.TeamId.Value));
                }

                statTableDto.PlayerRows = goalieRows.GroupBy(a => a.Goalie, b => b, (skater, rows) => new PlayerTableRow()
                {
                    Player      = PlayerDto.Create(skater),
                    Season      = null,
                    Team        = null,
                    SeasonCount = rows.Select(a => a.Season).Distinct().Count(),
                    TeamCount   = rows.Where(x => x.GoalieId == skater.Id).Select(x => x.TeamId).Distinct().Count(),
                    Stats       = new int[]
                    {
                        rows.Sum(x => x.GamesPlayed),
                        rows.Sum(x => x.Wins),
                        rows.Sum(x => x.Losses),
                        rows.Sum(x => x.OvertimeLosses),
                        rows.Sum(x => x.Minutes),
                        rows.Sum(x => x.PenaltyMinutes),
                        rows.Sum(x => x.Shutouts),
                        rows.Sum(x => x.GoalsAgainst),
                        rows.Sum(x => x.ShotsAgainst),
                        rows.Sum(x => x.Assists),
                        rows.Sum(x => x.EmptyGoalAgainst),
                        rows.Sum(x => x.PenaltyShotSaves),
                        rows.Sum(x => x.PenaltyShotAttempts),
                        rows.Sum(x => x.Starts),
                        rows.Sum(x => x.Backups),
                    }
                })
                                          .ToList();

                statTableDto.PlayerRows = statTableDto.PlayerRows.OrderByDescending(a => a.Stats.ElementAt(cleanParameters.Col.Value)).ThenByDescending(a => a.Stats.ElementAt(4));
                AddRanks(statTableDto.PlayerRows, 1 + (cleanParameters.Page.Value * pageSize));
            }

            statTableDto.DisplayType    = "career";
            statTableDto.PlayerType     = "goalie";
            statTableDto.StatParameters = cleanParameters;
            return(statTableDto);
        }
示例#26
0
        public StatTableDto GetPlayerGoalieTable(int goalieId, StatParametersDto paramDto)
        {
            StatTableDto      statTableDto    = new StatTableDto();
            StatParametersDto cleanParameters = CleanPlayerParameters(paramDto);

            using (db = new BojoBoxContext())
            {
                LeagueDto leagueDto = GetLeague(cleanParameters.League.Value);
                TeamDto   teamDto   = GetTeam(cleanParameters.Team.Value);
                PlayerDto goalieDto = GetGoalie(goalieId);

                statTableDto.HeaderText = goalieDto.Name;

                var goalieSeasonsQuery = db.GoalieSeasons
                                         .Include(a => a.Goalie)
                                         .Include(a => a.Team)
                                         .Include(a => a.League)
                                         .Where(a => a.GoalieId == goalieDto.Id);

                bool isPlayoffs = CheckIfPlayoffs(cleanParameters.SeasonType.Value);
                goalieSeasonsQuery = goalieSeasonsQuery.Where(a => a.isPlayoffs == isPlayoffs);

                if (cleanParameters.League > 0)
                {
                    goalieSeasonsQuery = goalieSeasonsQuery.Where(a => a.LeagueId == leagueDto.Id);
                }

                int teamCount = goalieSeasonsQuery.Where(a => a.Team != null).Select(a => a.Team.Id).Distinct().Count();

                statTableDto.Teams = goalieSeasonsQuery.Select(a => a.Team).Where(a => a != null).DistinctBy(a => a.Id).Select(a => TeamDto.Create(a)).ToList();

                if (cleanParameters.Team > 0)
                {
                    goalieSeasonsQuery = goalieSeasonsQuery.Where(a => a.TeamId == cleanParameters.Team);
                }
                else
                {
                    goalieSeasonsQuery = goalieSeasonsQuery.Where(a => a.SubtotalForId == null);
                }

                List <GoalieSeasonFullDto> goalieSeasonDtos = goalieSeasonsQuery.Select(a => GoalieSeasonFullDto.Create(a)).ToList();

                int i = 1;
                List <PlayerTableRow> rows = new List <PlayerTableRow>();
                foreach (var dto in goalieSeasonDtos)
                {
                    PlayerTableRow row = new PlayerTableRow();
                    row.Player = dto.Goalie;
                    row.Rank   = i++;
                    row.Season = dto.Season;
                    row.Team   = dto.Team;
                    row.Stats  = GetGoalieStats(dto);
                    rows.Add(row);
                }

                if (cleanParameters.Col == null)
                {
                    rows = rows.OrderByDescending(a => a.Season).ToList();
                }
                else
                {
                    rows = rows.OrderByDescending(a => a.Stats.ElementAt(cleanParameters.Col.Value)).ThenByDescending(a => a.Stats.ElementAt(13)).ToList();
                }

                statTableDto.PlayerRows = rows;

                List <int> totals = new List <int>();
                if (rows.Any())
                {
                    totals = GetTotals(rows);
                    totals.Insert(0, teamCount);
                    totals.Insert(0, rows.Count());
                }
                statTableDto.Totals = totals;
            }

            statTableDto.DisplayType    = "player";
            statTableDto.PlayerType     = "goalie";
            statTableDto.StatParameters = cleanParameters;
            return(statTableDto);
        }
示例#27
0
 public void Update(LeagueDto league)
 {
     UpdateLeague(league);
 }
示例#28
0
 public void AddNew(LeagueDto league)
 {
     InsertLeague(league);
 }
示例#29
0
 public static void WrapIn(this LeagueDto dto, League league, HemaneContext context)
 {
     league.Name  = dto.Name;
     league.Sport = context.Sports.Single(s => s.Id == dto.SportId);
 }
示例#30
0
 public bool HasAccess(LeagueDto leagueDto)
 {
     return(this._userService.CurrentUser().Group == Group.Administrator);
 }