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.")); }
public IHttpActionResult Leave(Int32 eventID, Int32 tournamentID) { BaseViewModel viewmodel = new BaseViewModel(); TournamentParticipantDataController participantDataCtrl = new TournamentParticipantDataController(); TournamentTeamParticipantDataController teamParticipantDataCtrl = new TournamentTeamParticipantDataController(); try { var participant = participantDataCtrl.GetItems().SingleOrDefault(x => x.TournamentID == tournamentID && x.UserID == UserHelper.CurrentUserID); if (participant != null) { participantDataCtrl.Delete(participant.ID); } else { var teamParticipant = teamParticipantDataCtrl.GetItemByTournament(tournamentID); if (teamParticipant != null) { teamParticipantDataCtrl.Delete(teamParticipant.ID); } else { return(Warning(viewmodel, "Du bist nicht angemeldet.")); } } } catch (Exception ex) { return(Error(viewmodel, ex)); } return(Ok(viewmodel, "Abmeldung erfolgreich.")); }
public static AccountTournamentViewModelItem FromModel(this AccountTournamentViewModelItem viewmodel, User model) { TournamentParticipantDataController participantDataCtrl = new TournamentParticipantDataController(); viewmodel.Name = $"{model.FirstName} {model.LastName}"; viewmodel.Image = Properties.Settings.Default.imageAbsolutePath + "team/no_image.png"; // TODO viewmodel.TournamentParticipation.AddRange(participantDataCtrl.GetItems().Where(x => x.User.ID == model.ID && x.Tournament.Event.End > DateTime.Now).ToList().ConvertAll(x => { return(new AccountTournamentParticipantViewModelItem().FromModel(x.Tournament)); })); return(viewmodel); }