private UIElement Add(IEnumerable <string> sportNames)
        {
            TournamentCreateViewModel viewModel = new TournamentCreateViewModel(sportNames);
            TournamentCreateControl   control   = new TournamentCreateControl(viewModel);

            viewModel.TournamentCreated += (s, e) =>
            {
                TournamentBaseModel tournamentCreateModel = e.Tournament;
                TournamentBaseDTO   tournamentCreateDTO   = Mapper.Map <TournamentBaseModel, TournamentBaseDTO>(tournamentCreateModel);

                using (ITournamentService service = factory.CreateTournamentService())
                {
                    ServiceMessage serviceMessage = service.Create(tournamentCreateDTO);
                    RaiseReceivedMessageEvent(serviceMessage.IsSuccessful, serviceMessage.Message);

                    if (serviceMessage.IsSuccessful)
                    {
                        Notify();
                        viewModel.Name = String.Empty;
                    }
                }
            };

            return(control);
        }
Exemple #2
0
        // GET: Tournament/Create
        public ActionResult Create()
        {
            var vm = new TournamentCreateViewModel();

            //vm.Tournament.NumberOfMeetings = 1;
            return(View(vm));
        }
        public IActionResult CreateTournament(TournamentCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName1 = ProcessUploadFile(model.Image1);
                string uniqueFileName2 = ProcessUploadFile(model.Image2);

                Tournament newTournament = new Tournament {
                    Name               = model.Name,
                    Email              = model.Email,
                    CityId             = model.CityId,
                    Description        = model.Description,
                    SportId            = model.SportId,
                    Phone              = model.Phone,
                    PriceParticipation = model.PriceParticipation,
                    PricePerGame       = model.PricePerGame,
                    IsPayed            = model.IsPayed,
                    Image1Path         = uniqueFileName1,
                    Image2Path         = uniqueFileName2
                };

                tournamentRepository.Add(newTournament);

                return(RedirectToAction("Details", "Tournament", new { id = newTournament.Id }));
            }
            var tournament = new TournamentCreateViewModel {
                Cities = sportObjectRepository.GetAllCities(),
                Sports = sportObjectRepository.GetAllSports()
            };

            return(View("CreateTournament", tournament));
        }
        public ActionResult Create()
        {
            //TODO if player is already in active tournament, redirect to this tournamnet gameplay page
            TournamentCreateViewModel model = new TournamentCreateViewModel(GlobalConfig.Connection.GetGameNames());

            return(View(model));
        }
        public IActionResult CreateTournament()
        {
            var model = new TournamentCreateViewModel {
                Cities = sportObjectRepository.GetAllCities(),
                Sports = sportObjectRepository.GetAllSports()
            };

            return(View(model));
        }
Exemple #6
0
        //public ActionResult Create([Bind(Include = "Id,Rounds,TournamentName")] Tournament tournament)
        public ActionResult Create(TournamentCreateViewModel vm, PlayerCreateViewModel players, List <int> playerIds)
        {
            var userId = User.Identity.GetUserId();

            vm.Tournament.UserId = userId;



            if (ModelState.IsValid)
            {
                db.Tournaments.Add(vm.Tournament);
                db.SaveChanges();
                var tournamentId = vm.Tournament.Id;

                if (string.IsNullOrEmpty(userId))
                {
                    HttpCookie cookie = new HttpCookie("TournamentAdministrator");
                    cookie.Value = tournamentId.ToString();
                    cookie.Expires.AddDays(30d);
                    Response.Cookies.Add(cookie);
                }

                var playerList = new List <Player>();
                var tmpPlayer  = new Player();

                foreach (var playerName in players.NewPlayerList)
                {
                    tmpPlayer.PlayerName = playerName;
                    //tmpPlayer.UserId = userId;
                    db.Players.Add(tmpPlayer);
                    db.SaveChanges();
                    playerList.Add(new Player()
                    {
                        PlayerName = tmpPlayer.PlayerName, Id = tmpPlayer.Id
                    });
                }
                //if (playerIds.Any())
                //{
                //    var existingPlayers = db.Players.Where(p => playerIds.Contains(p.Id)).ToList();
                //    playerList.AddRange(existingPlayers);
                //}

                var games = this.tournamentHelper.GenerateGames(playerList, vm.Tournament.NumberOfMeetings, tournamentId);
                db.Games.AddRange(games);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = tournamentId }));
            }

            return(View());
        }
        public ActionResult Create(TournamentCreateViewModel model)
        {
            string creatorId = User.Identity.GetUserId();

            //get creator
            Player lobbyCreator = GlobalConfig.Connection.GetPlayer_ByOwnerId(creatorId);
            //get gameType
            string gameType = model.SelectedGame;
            //TOOD Create New Lobby;
            int?lobbyId;

            try
            {
                lobbyId = GlobalConfig.Connection.CreateLobby(lobbyCreator, gameType);
            }
            catch (Exception e)
            {
                string p = e.Message;
                return(Redirect("Create"));
            }
            //Redirect to this lobby if creation went succesfully
            return(RedirectToAction("Lobby", new { lobbyId = lobbyId }));//View();
        }
Exemple #8
0
 public TournamentCreateControl(TournamentCreateViewModel viewModel)
 {
     InitializeComponent();
     this.DataContext = viewModel;
 }