Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PostLeague([FromBody] LeagueDTO leagueDTO)
        {
            //if model state is not valid send bad request response
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //get all leagues
            IEnumerable <League> leagues = await _repository.Leagues().GetAllAsync();

            //if there is a league in the repository already send bad request response
            if (leagues.Count() > 0)
            {
                return(new ConflictActionResult(Request, "There is already a league in the repository!" +
                                                " We allow only one league to exist."));
            }

            var league = _factory.GeTModel(leagueDTO);

            //try to insert the league into the repository
            try { int result = await _repository.Leagues().InsertAsync(league); }
            catch (Exception) { throw; }

            //InsertAsync(league) created new id, so leagueDTO must reflect that
            leagueDTO = _factory.GetDTO(league);

            //send created at route response
            return(Created <LeagueDTO>(Request.RequestUri + "/id/" + leagueDTO.Id.ToString(), leagueDTO));
        }
Ejemplo n.º 2
0
        private void SetRankingInformation(LeagueSummoner summoner, SummonerDTO summonerDto)
        {
            ICollection <LeagueDTO> leagueDtos = _leagueRequestService.GetLeagues(summonerDto.Id);

            if (leagueDtos == null)
            {
                summoner.Tier     = "Unranked";
                summoner.Division = "";
                return;
            }

            LeagueDTO rankedSoloLeagueDto = leagueDtos.FirstOrDefault(l => l.Queue == _rankedSolo);

            if (rankedSoloLeagueDto == null)
            {
                summoner.Tier     = "Unranked";
                summoner.Division = "";
            }
            else
            {
                summoner.Tier = rankedSoloLeagueDto.Tier.ToCapitalized();

                //For solo queue there's only one entry, so we can just get it
                LeagueEntryDTO entryDto = rankedSoloLeagueDto.Entries.First();

                summoner.Division     = IsDivisionRequired(summoner.Tier) ? entryDto.Division : "";
                summoner.LeaguePoints = entryDto.LeaguePoints;
            }
        }
Ejemplo n.º 3
0
 public DailySummaryDO(DateTime GameDate, LeagueDTO oLeagueDTO, string ConnectionString, string strLoadDateTime)
 {
     _GameDate         = GameDate;
     _oLeagueDTO       = oLeagueDTO;
     _ConnectionString = ConnectionString;
     _strLoadDateTime  = strLoadDateTime;
 }
Ejemplo n.º 4
0
        private async void AddConfirm_Click(object sender, RoutedEventArgs e)
        {
            MemberDTO member = (MemberDTO)AddPickerMember.SelectedItem;
            LeagueDTO league = (LeagueDTO)AddPickerLeague.SelectedItem;

            List <Control> controls = new List <Control>
            {
                AddGameNr,
                AddGameDate
            };

            if (!ValidateGame(controls, AddError))
            {
                return;
            }

            GameDTO game = new GameDTO
            {
                GameNumber = AddGameNr.Text,
                MemberId   = member.Id,
                LeagueId   = league.Id,
                Date       = (DateTime)AddGameDate.SelectedDate
            };

            await gamesProcessor.Add(game);

            ClearFields(controls);
            AddPickerMember.SelectedIndex = 0;
            AddPickerLeague.SelectedIndex = 0;

            MessageBox.Show("De wedstrijd werd toegevoegd.", "Succes");
        }
Ejemplo n.º 5
0
        private async void ModifyConfirm_Click(object sender, RoutedEventArgs e)
        {
            GameDTO        game     = (GameDTO)ModifyPickerGame.SelectedItem;
            List <Control> controls = new List <Control> {
                ModifyGameDate
            };

            if (!ValidateGame(controls, ModifyError))
            {
                return;
            }

            MemberDTO member = (MemberDTO)ModifyPickerMember.SelectedItem;
            LeagueDTO league = (LeagueDTO)ModifyPickerLeague.SelectedItem;

            game.MemberId = member.Id;
            game.LeagueId = league.Id;
            game.Date     = (DateTime)ModifyGameDate.SelectedDate;

            await gamesProcessor.Update(game);

            ModifyPickerGame.SelectedIndex = 0;

            MessageBox.Show("De wedstrijd werd aangepast.", "Succes");
        }
Ejemplo n.º 6
0
 // Constructor
 public TableTemplate(DateTime GameDate, LeagueDTO oLeagueDTO, string ConnectionString, string strLoadDateTime)
 {
     _GameDate         = GameDate;
     _oLeagueDTO       = oLeagueDTO;
     _ConnectionString = ConnectionString;
     _strLoadDateTime  = strLoadDateTime;
 }
Ejemplo n.º 7
0
 public RotationDO(SortedList <string, CoversDTO> ocRotation, DateTime GameDate, LeagueDTO oLeagueDTO, string ConnectionString, string strLoadDateTime)
 {
     _ocRotation       = ocRotation;
     _GameDate         = GameDate;
     _oLeagueDTO       = oLeagueDTO;
     _ConnectionString = ConnectionString;
     _strLoadDateTime  = strLoadDateTime;
 }
Ejemplo n.º 8
0
        public LeagueInfoDO(string LeagueName, LeagueDTO oLeagueDTO, string ConnectionString)
        {
            int rows = SysDAL.DALfunctions.ExecuteSqlQuery(ConnectionString, getRowSql(LeagueName), null, oLeagueDTO, PopulateDTO);

            if (rows == 0)
            {
                throw new Exception($"LeagueInfo row not found for League: {LeagueName}");
            }
        }
Ejemplo n.º 9
0
        static void PopulateDTO(List <object> ocRows, object oRow, SqlDataReader rdr)
        {
            LeagueDTO oLeagueDTO = (LeagueDTO)oRow;

            oLeagueDTO.LeagueName       = rdr["LeagueName"].ToString().Trim();
            oLeagueDTO.Periods          = (int)rdr["Periods"];
            oLeagueDTO.MinutesPerPeriod = (int)rdr["MinutesPerPeriod"];
            oLeagueDTO.OverTimeMinutes  = (int)rdr["OverTimeMinutes"];
            oLeagueDTO.MultiYearLeague  = (bool)rdr["MultiYearLeague"];
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Put(Guid id, [FromBody] LeagueDTO value)
        {
            if (id != value.Id)
            {
                return(this.BadRequest("Posted league Id does not match the request."));
            }
            IActionResult result = await Execute(_log, async() => await _leagueService.Upsert(value));

            return(result);
        }
Ejemplo n.º 11
0
 public HttpResponseMessage PostLeague([FromBody] LeagueDTO role)
 {
     if (logic.Create(role))
     {
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     else
     {
         return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }
Ejemplo n.º 12
0
 public HttpResponseMessage UpdateLeague([FromBody] LeagueDTO role)
 {
     if (logic.Update(role))
     {
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     else
     {
         return(new HttpResponseMessage(HttpStatusCode.NotFound));
     }
 }
        public IHttpActionResult UpdateLeague([FromBody] LeagueDTO leagueDto)
        {
            league leagueMap = AutoMapper.Mapper.Map <LeagueDTO, league>(leagueDto);
            league l;

            using (var context = new escorcenterdbEntities())
            {
                l = (from r in context.leagues where r.Id == leagueMap.Id select r).FirstOrDefault();
                l = leagueMap;
                context.SaveChanges();
            }
            return(Ok(l));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates the specified league.
        /// </summary>
        /// <param name="leagueDto">The entity.</param>
        /// <returns>The league that was created.</returns>
        public async Task <LeagueDTO> Create(LeagueDTO leagueDto)
        {
            var result = await this.Handler.Execute(_log, async() =>
            {
                League league = _leagueFactory.CreateDomainObject(leagueDto);
                league.Validate();

                league = await _leagueRepository.Create(league);
                return(_leagueMapper.ToDto(league));
            });

            return(result);
        }
        public IHttpActionResult CreateLeague([FromBody] LeagueDTO _league)
        {
            league l = new league()
            {
                Name = _league.Name, Description = _league.Description, Enabled = true, Region = _league.Region
            };

            using (var context = new escorcenterdbEntities())
            {
                context.leagues.Add(l);
                context.SaveChanges();
            }
            return(Ok(l));
        }
        public async void ReturnNullWhenLeagueDoNotExistsInDbByGivenId()
        {
            // Assert
            LeagueDTO testLeague = null;

            _repositoryMock.Reset();
            _repositoryMock.Setup(r => r.GetByIdAsync(It.IsAny <uint>())).ReturnsAsync((League)null);

            // Act
            var err = await Record.ExceptionAsync(async
                                                      () => testLeague = await _service.GetByIdAsync(1));

            // Arrange
            err.Should().BeNull();

            testLeague.Should().BeNull();
        }
Ejemplo n.º 17
0
        public async void GetLeagueByIdOk(int id)
        {
            // Arrange
            LeagueDTO returnedLeague = null;

            // Act
            var response = await _client.GetAsync($"api/leagues/{id}");

            response.EnsureSuccessStatusCode();

            var responseString = await response.Content.ReadAsStringAsync();

            var deserializeErr = Record.Exception(()
                                                  => returnedLeague = JsonConvert.DeserializeObject <LeagueDTO>(responseString));


            // Assert
            Assert.Null(deserializeErr);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(returnedLeague);
        }
        public IHttpActionResult GetLeagueById(long id = 0)
        {
            league _league = null;

            team[] _teams;
            using (var context = new escorcenterdbEntities())
            {
                _league = (from l in context.leagues where l.Id == id && l.Enabled == true select l).FirstOrDefault <league>();
                _teams  = (from t in context.teams where t.League == id && t.Enabled == true select t).ToArray <team>();
            }

            if (_league == null)
            {
                return(NotFound());
            }

            LeagueDTO league = AutoMapper.Mapper.Map <LeagueDTO>(_league);

            TeamDTO[] teams = AutoMapper.Mapper.Map <team[], TeamDTO[]>(_teams.ToArray());
            league.teams.AddRange(teams);
            return(Ok(league));
        }
Ejemplo n.º 19
0
        public async Task <IHttpActionResult> EditLeague([FromUri] int id, [FromBody] LeagueDTO leagueDTO)
        {
            //if id from URI matches Id from request body send bad request response
            if (id != leagueDTO.Id)
            {
                return(BadRequest("The id from URI: " + id + " doesn't match the" +
                                  " Id from request body: " + leagueDTO.Id + "!"));
            }

            //if model state is not valid send bad request response
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            League league;

            //try to get requested league
            try { league = await _repository.Leagues().FindSingleAsync(l => l.Id == id); }
            catch (InvalidOperationException) { throw; }

            //if doesn't exist send not found response
            if (league == null)
            {
                return(new NotFoundActionResult(Request, "Could not find league id=" + id + "."));
            }

            //leagueDTO is ok, update the league's properties
            league.Name         = leagueDTO.Name;
            league.NextFixtures = leagueDTO.NextFixtures;
            league.Week         = leagueDTO.Week;

            //try to update repository
            try { int result = await _repository.Leagues().UpdateAsync(league); }
            catch (Exception) { throw; }

            //send no content response
            return(Ok("League Id=" + id + " was successfully updated."));
        }
        public async void ReturnLeagueWhichExistsInDbByGivenId()
        {
            // Assert
            var league = new League()
            {
                Id      = 1,
                Name    = "Primera Division",
                Country = "Spain",
                Season  = "2018/2019",
                MVP     = new Player()
                {
                    Name = "Lionel", Surname = "Messi"
                },
                Winner = new Team()
                {
                    ShortName = "FC Barcelona"
                }
            };

            LeagueDTO testLeague = null;

            _repositoryMock.Reset();
            _repositoryMock.Setup(r => r.GetByIdAsync(It.IsAny <uint>())).ThrowsAsync(new ArgumentException());
            _repositoryMock.Setup(r => r.GetByIdAsync(1)).ReturnsAsync(league);

            var expectedLeague = _mapper.Map <LeagueDTO>(league);

            // Act
            var err = await Record.ExceptionAsync(async
                                                      () => testLeague = await _service.GetByIdAsync(1));

            // Arrange
            err.Should().BeNull();

            testLeague.Should().NotBeNull();

            testLeague.Should().BeEquivalentTo(expectedLeague);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Get informaiton about the league from the league register
        /// </summary>
        /// <param name="leagueName">Shortname of the league</param>
        /// <returns>DTO containing league information</returns>
        protected LeagueDTO GetLeagueRegisterInfo(string leagueName)
        {
            var register = LeagueRegister.Get();

            var leagueEntry = register.GetLeague(leagueName);

            if (leagueEntry == null)
            {
                return(null);
            }

            var leagueDto = new LeagueDTO()
            {
                Name              = leagueEntry.Name,
                LongName          = leagueEntry.PrettyName,
                CreatedByUserId   = leagueEntry.CreatorId.ToString(),
                CreatedByUserName = leagueEntry.CreatorName,
                CreatedOn         = leagueEntry.CreatedOn,
                LastModifiedOn    = leagueEntry.LastUpdate,
                OwnerUserId       = leagueEntry.OwnerId.ToString()
            };

            return(leagueDto);
        }
Ejemplo n.º 22
0
        public static void PopulateRotation(SortedList <string, CoversDTO> ocRotation, DateTime GameDate, LeagueDTO _oLeagueDTO, string ConnectionString, string strLoadDateTime)
        {
            RotationDO oRotation = new RotationDO(ocRotation, GameDate, _oLeagueDTO, ConnectionString, strLoadDateTime);

            oRotation.GetRotation();
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Post([FromBody] LeagueDTO value)
        {
            IActionResult result = await Execute(_log, async() => await _leagueService.Upsert(value));

            return(result);
        }
        public IHttpActionResult CreateNotification([FromBody] NotificationDTO _notification, TeamListDTO _teamList, LeagueDTO _league)
        {
            String         teamsId = "";
            List <TeamDTO> teams   = _teamList.items;

            foreach (TeamDTO t in teams)
            {
                teamsId = teamsId + "<" + t.Id + ">";
            }
            notification n = new notification {
                Content = _notification.Content, Date = DateTime.Parse(_notification.Date), Enabled = true, Title = _notification.Title, TeamsId = teamsId, LeagueId = (int)_league.Id
            };

            using (var context = new escorcenterdbEntities())
            {
                context.notifications.Add(n);
                context.SaveChanges();
            }
            return(Ok());
        }
Ejemplo n.º 25
0
 public League CreateDomainObject(LeagueDTO dto)
 {
     return(new League(dto.Id, dto.Name, dto.CreatedOn, (int)dto.Tier));
 }
Ejemplo n.º 26
0
        public List <SportDTO> GetActiveSports(BE.BaseRequest req)
        {
            SportEventsAccess seax = new SportEventsAccess();
            var successLogin       = true;

            if (!string.IsNullOrEmpty(req.LaunchToken) && string.IsNullOrEmpty(RequestContextHelper.SessionToken))
            {
                var response = UserWalletFacade.ProcessLogin(req);
                if (response.Status.Equals(BE.ResponseStatus.OK))
                {
                    //RequestContextHelper.SessionToken = response.GetData().SessionToken;
                    //RequestContextHelper.UserBalance = response.GetData().Balance;
                    //RequestContextHelper.UserName = response.GetData().NickName;

                    UserAccess ua   = new UserAccess();
                    BE.User    user = new BE.User();
                    user.LaunchToken  = req.LaunchToken;
                    user.SessionToken = response.GetData().SessionToken;
                    user.UID          = response.GetData().UserUID;
                    user.Balance      = response.GetData().Balance;
                    user.NickName     = response.GetData().NickName;

                    ua.LoginUser(user);
                    this.UpdateCurrentUserData(user);
                }
                else
                {
                    successLogin = false;
                    RequestContextHelper.LastError = response.Message;
                }
            }

            if (successLogin)
            {
                List <BE.Sport> sports = seax.GetActiveSports();

                List <SportDTO> sportsDto = new List <SportDTO>();

                string lastCode = null, lastRegion = null, lastCountry = null;

                foreach (var sport in sports.OrderBy(s => s.Code).ThenBy(s => s.RegionName).ThenBy(s => s.CountryName).ThenBy(s => s.Name))
                {
                    if (lastCode != sport.Code)
                    {
                        lastCode = sport.Code;
                        SportDTO         viewSport = new SportDTO();
                        List <RegionDTO> regions   = new List <RegionDTO>();

                        viewSport.Code = lastCode;
                        viewSport.Name = sport.Name;

                        foreach (var region in sports.Where(s => s.Code == lastCode).OrderBy(s => s.RegionName).ThenBy(s => s.CountryName).ThenBy(s => s.Name))
                        {
                            if (lastRegion != region.RegionID)
                            {
                                lastRegion = region.RegionID;
                                RegionDTO         newRegion = new RegionDTO();
                                List <CountryDTO> countries = new List <CountryDTO>();

                                newRegion.Name = region.RegionName;
                                newRegion.Code = region.RegionID;

                                #region paises
                                foreach (var pais in sports.Where(s => s.Code == lastCode && s.RegionID == lastRegion).OrderBy(s => s.CountryName).ThenBy(s => s.TournamentName))
                                {
                                    if (lastCountry != pais.Country)
                                    {
                                        CountryDTO       country = new CountryDTO();
                                        List <LeagueDTO> leagues = new List <LeagueDTO>();

                                        lastCountry  = pais.Country;
                                        country.Code = pais.Country;
                                        country.Flag = pais.MenuFlagKey;
                                        country.Name = pais.CountryName;
                                        #region Ligas
                                        foreach (var liga in sports.Where(s => s.Code == lastCode && s.RegionID == lastRegion && s.Country == lastCountry).OrderBy(s => s.TournamentName))
                                        {
                                            LeagueDTO league = new LeagueDTO();
                                            league.Code = liga.TournamentID;
                                            league.Name = liga.TournamentName == "" ? liga.InternalName : liga.TournamentName;
                                            leagues.Add(league);
                                        }
                                        #endregion
                                        country.Leagues = leagues;
                                        countries.Add(country);
                                    }
                                }
                                #endregion
                                newRegion.Countries = countries;
                                regions.Add(newRegion);
                            }
                        }
                        viewSport.Regions = regions;

                        sportsDto.Add(viewSport);
                    }
                }
                return(sportsDto);
            }
            return(new List <SportDTO>());
        }