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); }