/// <summary> /// Initializes a new instance of the <see cref="TournamentReceivedEventArgs"/> class /// </summary> /// <param name="tournament">a <see cref="TournamentDTO"/> representing the received tournament</param> /// <param name="culture">Culture of the tournament data</param> public TournamentReceivedEventArgs(TournamentDTO tournament, CultureInfo culture) { //Contract.Requires(tournament != null); Tournament = tournament; Culture = culture; }
private static void CompareTournament(TournamentDTO tournament, XElement element) { CompareEntity(tournament, element); CompareEntity(tournament.Sport, element.Element(GetXName("sport"))); CompareEntity(tournament.Category, element.Element(GetXName("category"))); }
public async Task <IActionResult> CreateTournament(TournamentDTO tournamentDto) { var username = GetUsername(); var tournament = await tournamentService.CreateTournament(tournamentDto, username); return(Ok(tournament)); }
/// <summary> /// Initializes a new instance of the <see cref="TournamentReceivedEventArgs"/> class /// </summary> /// <param name="tournament">a <see cref="TournamentDTO"/> representing the received tournament</param> /// <param name="culture">Culture of the tournament data</param> public TournamentReceivedEventArgs(TournamentDTO tournament, CultureInfo culture) { //Guard.Argument(tournament, nameof()).NotNull(); Tournament = tournament; Culture = culture; }
public TournamentDTO ToDTO(Tournament tournament) { var dto = new TournamentDTO() { Id = tournament.Id, Name = tournament.Name, CreationDate = tournament.CreationDate, StartDate = tournament.StartDate, PlayerIds = new List <int>(), DrawIds = new List <int>() }; if (tournament.Players != null && tournament.Players.Count > 0) { foreach (var player in tournament.Players) { dto.PlayerIds.Add(player.Id); } } if (tournament.Draws != null && tournament.Draws.Count > 0) { foreach (var draw in tournament.Draws) { dto.DrawIds.Add(draw.Id); } } return(dto); }
public void TournamentDTOMappingTest() { var msg = RMF.GetTournament(); var dto = new TournamentDTO(msg); ValidateTournament(msg, dto); }
public TournamentManagerErrorCodes CreateTournament(TournamentDTO tournamentDTO) { if (tournamentDTO.BuyIn > 0 && (tournamentDTO.BuyIn * tournamentDTO.Size) >= tournamentDTO.Prize) { return(TournamentManagerErrorCodes.BuyInMoreOrEqualToPrize); } if (tournamentDTO.OrganisationID == "null" && tournamentDTO.UserID == "null") { return(TournamentManagerErrorCodes.NoHost); } tournamentDTO.ID = idGenerator.GenerateID(12); if (tournamentDTO.OrganisationID == "null") { tournamentDTO.OrganisationID = null; int extraCost = tournamentDTO.Prize - (tournamentDTO.BuyIn * tournamentDTO.Size); if (userDB.GetCurrency(tournamentDTO.UserID) < extraCost) { return(TournamentManagerErrorCodes.NotEnoughMoney); } } else { tournamentDTO.UserID = null; } tournamentDB.CreateTournament(tournamentDTO); return(TournamentManagerErrorCodes.NoError); }
public void CreateTournament_PrizeLessThanUserCurrency_Test() { //Arrange TournamentManager tournament = new TournamentManager("Test"); TournamentDTO tournamentDTO = new TournamentDTO() { ID = "", Name = "Test Tournament", OrganisationID = "null", UserID = "021d968c-b151-4399-903e-19d867f08e5a", Size = 32, Prize = 9, BuyIn = 0, Game = Games.CounterStrike, StartTime = new DateTime(2021, 2, 1, 12, 00, 00), Status = TourneyStatus.Planned, TeamSize = 1 }; //Act var result = tournament.CreateTournament(tournamentDTO); //Assert Assert.AreEqual(TournamentManagerErrorCodes.NoError, result); }
public void CreateTournament_NoHost_Test() { //Arrange TournamentManager tournament = new TournamentManager("Test"); TournamentDTO tournamentDTO = new TournamentDTO() { ID = "", Name = "Test Tournament", OrganisationID = "null", UserID = "null", Size = 32, Prize = 0, BuyIn = 0, Game = Games.CounterStrike, StartTime = new DateTime(2021, 2, 1, 12, 00, 00), Status = TourneyStatus.Planned, TeamSize = 1 }; //Act var result = tournament.CreateTournament(tournamentDTO); //Assert Assert.AreEqual(TournamentManagerErrorCodes.NoHost, result); }
public void Create(TournamentDTO tournamentDTO) { var mapper = config.CreateMapper(); var tournament = mapper.Map <TournamentDTO, Tournament>(tournamentDTO); tournament.Prizes = mapper.Map <List <PrizeDTO>, List <Prize> >(tournamentDTO.Prizes); repository.Create(tournament); }
public IActionResult Put(TournamentDTO dto) { var input = _mapper.FromDTO(dto); var result = _tournamentService.Update(input); return(Ok(_mapper.ToDTO(result))); }
public void EditTournament(Guid id, TournamentDTO tournament) { var tournamentToEdit = _applicationDbContext.Tournaments.Find(id); tournamentToEdit.UpdateTournament(tournament.Matches, tournament.Name); _applicationDbContext.Tournaments.Update(tournamentToEdit); _applicationDbContext.SaveChanges(); }
public void CreateTournament(TournamentDTO tournamentDto) { var tournament = Tournament.CreateTournament(); tournament.UpdateTournament(tournamentDto.Matches, tournamentDto.Name); _applicationDbContext.Tournaments.Add(tournament); _applicationDbContext.SaveChanges(); }
public Response <TournamentDTO> Post([FromBody] TournamentDTO tournamentDto) { Response <TournamentDTO> response = new Response <TournamentDTO>(); Tournament t = tournamentDto.ConvertToTournament(null); _tournamentAppCRDService.Save(t); response.data = tournamentDto.ConvertTournamentToDTO(t); response.messages = _tournamentAppCRDService.GetMessages(); return(response); }
public Response <TournamentDTO> Put([FromBody] TournamentDTO tournamentDto) { Response <TournamentDTO> response = new Response <TournamentDTO>(); Tournament newtournament = _tournamentAppCRDService.GetById(tournamentDto.Id); newtournament = tournamentDto.ConvertToTournament(newtournament); _tournamentAppCRDService.Update(newtournament); response.data = tournamentDto.ConvertTournamentToDTO(newtournament); response.messages = _tournamentAppCRDService.GetMessages(); return(response); }
private void SaveTournamentDataToSportEventCache(TournamentDTO tournamentDto, URN secondId, CultureInfo culture) { CacheAddDtoItem(tournamentDto.Id, tournamentDto, culture, DtoType.Tournament, null); if (secondId != null && !Equals(tournamentDto.Id, secondId)) { var tourInfoDto = new TournamentInfoDTO(tournamentDto); var newTournamentDto = new TournamentInfoDTO(tourInfoDto, tourInfoDto.Season != null, tourInfoDto.CurrentSeason != null); CacheAddDtoItem(secondId, newTournamentDto, culture, DtoType.TournamentInfo, null); } }
public ActionResult <TournamentDTO> GetTournament(int id) { TournamentDTO tournament = _tournamentRepository.GetByIdDTO(id); if (tournament == null) { return(NotFound()); } return(tournament); }
private static void ValidateTournament(tournament msg, TournamentDTO dto) { Assert.AreEqual(msg.id, dto.Id.ToString()); Assert.AreEqual(msg.name, dto.Name); Assert.AreEqual(msg.category.id, dto.Category.Id.ToString()); Assert.AreEqual(msg.category.name, dto.Category.Name); Assert.AreEqual(msg.sport.id, dto.Sport.Id.ToString()); Assert.AreEqual(msg.sport.name, dto.Sport.Name); Assert.AreEqual(msg.scheduled, dto.Scheduled); Assert.AreEqual(msg.scheduled_end, dto.ScheduledEnd); //Assert.AreEqual(msg.tournament_length, dto.tour); //TODO: tournament_length missing }
public IActionResult Post([FromBody] TournamentDTO tournamentDto) { TitleShorcutGenerator shorcutGenerator = new TitleShorcutGenerator(tournamentDto); shorcutGenerator.generate(); Tournament tournament = tournamentDto.ToTournament(); _databaseContext.Tournaments.Add(tournament); _databaseContext.Players.AddRange(tournament.Players); _databaseContext.SaveChanges(); return(Ok()); }
public Tournament FromDTO(TournamentDTO dto) { var tournament = new Tournament() { Id = dto.Id, Name = dto.Name, CreationDate = dto.CreationDate.Equals(DateTime.MinValue) ? DateTime.Now :dto.CreationDate, StartDate = dto.StartDate }; return(tournament); }
public async Task <ActionResult <TournamentDTO> > AddOrEditTournament([FromBody] TournamentDTO tournamentDto) { var updatedTournament = await TournamentService.AddOrEditTournament(tournamentDto); if (tournamentDto.Id > 0) { return(NoContent()); } var uri = "api/tournament"; return(Created(uri, updatedTournament)); }
private static void ValidateTournamentExtended(tournamentExtended msg, TournamentDTO dto) { Assert.AreEqual(msg.id, dto.Id.ToString()); Assert.AreEqual(msg.name, dto.Name); Assert.AreEqual(msg.category.id, dto.Category.Id.ToString()); Assert.AreEqual(msg.category.name, dto.Category.Name); Assert.AreEqual(msg.sport.id, dto.Sport.Id.ToString()); Assert.AreEqual(msg.sport.name, dto.Sport.Name); Assert.AreEqual(msg.scheduled, dto.Scheduled); Assert.AreEqual(msg.scheduled_end, dto.ScheduledEnd); Assert.AreEqual(msg.current_season.id, dto.CurrentSeason.Id.ToString()); // TODO: extended properties are lost }
public static Tournament ToTournament(this TournamentDTO tournamentDto) { Tournament tournament = new Tournament { Players = tournamentDto.Players, Date = tournamentDto.Date, Id = tournamentDto.Id, Location = tournamentDto.Location, Name = tournamentDto.Name }; return(tournament); }
public ActionResult <TournamentDTO> DeleteTournament(int id) { TournamentDTO tournament = _tournamentRepository.GetByIdDTO(id); if (tournament == null) { return(NotFound()); } _tournamentRepository.Delete(tournament.TournamentId); _tournamentRepository.SaveChanges(); return(tournament); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] TournamentDTO tournamentDTO) { var tournament = await tournamentService.UpdateTournamentAsync(id, tournamentDTO); if (tournament == null) { return(NotFound()); } else { return(Ok(tournament)); } }
public async Task <ActionResult> Post([FromBody] TournamentDTO tournamentDTO) { var dto = await tournamentService.InsertTournamentAsync(tournamentDTO); if (dto == null) { return(BadRequest()); } else { return(Created($"api/tournaments/{dto.Id}", dto)); } }
public Tournament(TournamentDTO tournamentDTO) { ID = tournamentDTO.ID; Name = tournamentDTO.Name; OrganisationID = tournamentDTO.OrganisationID; UserID = tournamentDTO.UserID; Size = tournamentDTO.Size; Prize = tournamentDTO.Prize; BuyIn = tournamentDTO.BuyIn; Game = tournamentDTO.Game; StartTime = tournamentDTO.StartTime; Status = tournamentDTO.Status; TeamSize = tournamentDTO.TeamSize; }
public Tournament(TournamentDTO tournamentDTO, string source) { ID = tournamentDTO.ID; Name = tournamentDTO.Name; OrganisationID = tournamentDTO.OrganisationID; UserID = tournamentDTO.UserID; Size = tournamentDTO.Size; Prize = tournamentDTO.Prize; BuyIn = tournamentDTO.BuyIn; Game = tournamentDTO.Game; StartTime = tournamentDTO.StartTime; Status = tournamentDTO.Status; TeamSize = tournamentDTO.TeamSize; tournamentDB = TournamentFactory.GetTournamentDB(source); }
public async Task <TournamentDTO> UpdateTournamentAsync(int id, TournamentDTO tournamentDTO) { var existedTournament = await database.TournamentRepository.GetEntityByIdAsync(id); var tournament = mapper.Map <TournamentDTO, Tournament>(tournamentDTO); tournament.Id = id; tournament.CreateUserId = existedTournament.CreateUserId; tournament.CreateDate = existedTournament.CreateDate; tournament.ModDate = DateTime.Now; var updatedTournament = database.TournamentRepository.UpdateEntity(tournament); var updatedTournamentDTO = mapper.Map <Tournament, TournamentDTO>(updatedTournament); bool isSaved = await database.SaveAsync(); return((isSaved == true) ? updatedTournamentDTO : null); }
public async Task <TournamentDTO> InsertTournamentAsync(TournamentDTO tournamentDTO) { var tournamentToInsert = mapper.Map <TournamentDTO, Tournament>(tournamentDTO); var insertedTournament = await database.TournamentRepository.InsertEntityAsync(tournamentToInsert); bool isSaved = await database.SaveAsync(); if (isSaved == false) { return(null); } else { return(mapper.Map <Tournament, TournamentDTO>(insertedTournament)); } }