public static TournamentViewModelItem FromModel(this TournamentViewModelItem viewmodel, Tournament model) { Int32 UserID = UserHelper.CurrentUserID; viewmodel.ID = model.ID; viewmodel.GameID = model.TournamentGameID; viewmodel.TeamSize = model.TeamSize; viewmodel.ChallongeLink = model.ChallongeLink; viewmodel.Mode = model.Mode; viewmodel.Start = model.Start; viewmodel.End = model.End; if (model.TournamentGame != null) { viewmodel.GameTitle = model.TournamentGame.Name; viewmodel.Rules = model.TournamentGame.Rules; viewmodel.Image = Properties.Settings.Default.imageAbsolutePath + model.TournamentGame.Image; } viewmodel.Event.FromModel(model.Event); viewmodel.Player = model.TournamentParticipant.ToList().ConvertAll(x => { if (x.UserID == UserID) { viewmodel.IsParticipant = true; } var vm = new TournamentParticipantViewModelItem(); vm.FromModel(x); return(vm); }); viewmodel.Teams = model.TournamentTeam.ToList().Where(x => x.TournamentTeamParticipant.Count > 0).ToList().ConvertAll(x => { if (x.TournamentTeamParticipant.FirstOrDefault(p => p.UserID == UserID) != null) { viewmodel.IsParticipant = true; } var vm = new TournamentTeamViewModelItem(); vm.FromModel(x); return(vm); }); if (model.Partner != null) { viewmodel.Partner.FromModel(model.Partner); } viewmodel.ParticipantCount = model.TournamentParticipant.Count; viewmodel.Teams.ForEach(team => viewmodel.ParticipantCount += team.Player.Count); return(viewmodel); }
// Tournament Team public static TournamentTeamViewModelItem FromModel(this TournamentTeamViewModelItem viewmodel, TournamentTeam model) { viewmodel.ID = model.ID; viewmodel.Name = model.Name; viewmodel.HasPassword = !String.IsNullOrEmpty(model.Password); viewmodel.Player = model.TournamentTeamParticipant.ToList().ConvertAll(x => { var vm = new TournamentParticipantViewModelItem(); vm.FromModel(x); return(vm); }); return(viewmodel); }