Ejemplo n.º 1
0
 public virtual IActionResult JoinTournament([FromBody] JoinTournamentRequest joinRequest)
 {
     mLogger.Info("", Codes.PlayerJoined, "Tournament join attempt", mReferenceId, joinRequest);
     mCore.TournamentsApi.JoinTournament(joinRequest);
     mLogger.Info("", Codes.PlayerJoined, "Tournament join success", mReferenceId);
     return(Ok());
 }
Ejemplo n.º 2
0
        public IHttpActionResult CreateTeam(Int32 eventID, Int32 tournamentID, CreateTeamRequest request)
        {
            BaseViewModel                           viewmodel               = new BaseViewModel();
            TournamentDataController                dataCtrl                = new TournamentDataController();
            SeatDataController                      seatDataCtrl            = new SeatDataController();
            TournamentTeamDataController            teamDataCtrl            = new TournamentTeamDataController();
            TournamentTeamParticipantDataController teamParticipantDataCtrl = new TournamentTeamParticipantDataController();

            try
            {
                if (seatDataCtrl.GetCurrentUserSeats(eventID).FindAll(x => x.State >= 2).Count == 0)
                {
                    return(Error(viewmodel, "Du bist kein Teilnehmer dieser Veranstaltung. Bitte reserviere einen Platz."));
                }

                var team = teamDataCtrl.Insert(request.ToModel(tournamentID));
                JoinTournamentRequest _tmp = new JoinTournamentRequest()
                {
                    TeamID = team.ID
                };
                teamParticipantDataCtrl.Insert(_tmp.ToTeamModel());
            }
            catch (Exception ex)
            {
                return(Error(viewmodel, ex));
            }

            return(Ok(viewmodel, "Team wurde erstellt."));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Join(Int32 eventID, Int32 tournamentID, JoinTournamentRequest request)
        {
            BaseViewModel      viewmodel    = new BaseViewModel();
            SeatDataController seatDataCtrl = new SeatDataController();
            TournamentParticipantDataController     participantDataCtrl     = new TournamentParticipantDataController();
            TournamentTeamParticipantDataController teamParticipantDataCtrl = new TournamentTeamParticipantDataController();

            try
            {
                if (seatDataCtrl.GetCurrentUserSeats(eventID).FindAll(x => x.State >= 2).Count == 0)
                {
                    return(Error(viewmodel, "Du bist kein Teilnehmer dieser Veranstaltung. Bitte reserviere einen Platz."));
                }

                if (request.TeamID == null)
                {
                    participantDataCtrl.Insert(request.ToModel(tournamentID));
                }
                else
                {
                    teamParticipantDataCtrl.Insert(request.ToTeamModel());
                }
            }
            catch (Exception ex)
            {
                return(Error(viewmodel, ex));
            }

            return(Ok(viewmodel, "Anmeldung erfolgreich."));
        }
Ejemplo n.º 4
0
        public static TournamentTeamParticipant ToTeamModel(this JoinTournamentRequest viewmodel)
        {
            TournamentTeamParticipant model = new TournamentTeamParticipant();

            model.UserID           = UserHelper.CurrentUserID;
            model.TournamentTeamID = viewmodel.TeamID ?? default(int);
            model.Registered       = DateTime.Now;

            return(model);
        }
Ejemplo n.º 5
0
        public static TournamentParticipant ToModel(this JoinTournamentRequest viewmodel, Int32 TournamentID)
        {
            TournamentParticipant model = new TournamentParticipant();

            model.UserID       = UserHelper.CurrentUserID;
            model.TournamentID = TournamentID;
            model.Registered   = DateTime.Now;

            return(model);
        }
Ejemplo n.º 6
0
        public TournamentPlayer JoinTournament(JoinTournamentRequest request)
        {
            new RequestValidator <JoinTournamentRequest>(request)
            .Assert();

            var tournament = mReposManager.TournamentsRepository.GetById(request.TournamentId);
            var invites    = tournament.IsOpen
                        ? null
                        : mReposManager.TournamentsRepository.FindTournamentInvite(request.TournamentId, request.UserId,
                                                                                   request.TeamId ?? Guid.Empty).ToList();

            if (!tournament.IsOpen && !invites.Any())
            {
                throw new BusinsessLogicException("NOTINVITED", "Not invited on closed tournament");
            }

            foreach (var playerInvite in invites.Where(el => el.Player.HasValue))
            {
                if (playerInvite.Used)
                {
                    throw new BusinsessLogicException("ALREADYPARTICIPATED", "Already in tournament");
                }
                mReposManager.TournamentsRepository.UseTournamentInvite(playerInvite.Id.Value);
            }

            var newPlayer = new TournamentPlayer
            {
                PlayerId     = request.UserId,
                TeamId       = request.TeamId,
                TournamentId = request.TournamentId
            };

            mReposManager.TournamentsRepository.AddTournamentPlayer(newPlayer);

            return(newPlayer);
        }