public void GetTournament_SpecificTournamentExist_TournamentReturned()
        {
            // Arrange
            var testData = new TournamentBuilder()
                           .WithId(1)
                           .WithName("test")
                           .WithDescription("Volley")
                           .WithScheme(TournamentSchemeEnum.Two)
                           .WithSeason(2016)
                           .WithRegulationsLink("volley.dp.ua")
                           .Build();

            MockGetTournament(testData, SPECIFIC_TOURNAMENT_ID);
            var expected = new TournamentViewModel
            {
                Id              = testData.Id,
                Name            = testData.Name,
                Description     = testData.Description,
                Scheme          = testData.Scheme.ToDescription(),
                Season          = testData.Season,
                RegulationsLink = testData.RegulationsLink
            };

            var sut = BuildSUT();

            // Act
            var result = sut.GetTournament(SPECIFIC_TOURNAMENT_ID);
            var actual = result as OkNegotiatedContentResult <TournamentViewModel>;

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult <TournamentViewModel>));
            TestHelper.AreEqual(expected, actual.Content, new TournamentViewModelComparer());
        }
示例#2
0
        public async Task <IActionResult> Edit(TournamentViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (ModelState.IsValid)
                {
                    string path = model.LogoPath;

                    if (model.LogoFile != null)
                    {
                        path = await _imageHelper.UploadImageAsync(model.LogoFile, "Tournaments");
                    }

                    if (model.EndDate.Date <= model.StartDate.Date)
                    {
                        ModelState.AddModelError(string.Empty, "The end date cannot be less than the start date");
                    }

                    TournamentEntity tournamentEntity = _converterHelper.ToTournamentEntity(model, path, false);
                    _context.Update(tournamentEntity);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }

            return(View(model));
        }
示例#3
0
        public ActionResult SaveScheduleInDB(List <Match> matches)
        {
            var tournamentId = matches[0].TournamentId;
            var matchesInDb  = _context.Matches.Where(c => c.TournamentId == tournamentId).ToList();

            foreach (var item in matchesInDb)
            {
                var match = matches.SingleOrDefault(c => c.Id == item.Id);
                item.StartTime     = match.StartTime;
                item.EndTime       = match.EndTime;
                item.PlayingDateId = match.PlayingDateId;
                item.CourtId       = match.CourtId;
                item.MatchDuration = match.MatchDuration;
                item.IsScheduled   = true;
            }
            _context.SaveChanges();
            var tn = _context.Tournaments
                     .Include(c => c.Classes.Select(x => x.PlayingDates))
                     .SingleOrDefault(c => c.Id == tournamentId);

            var viewModel = new TournamentViewModel();

            viewModel.Tournament = tn;
            viewModel.Classes    = tn.Classes.ToList();
            return(View("Schedule2", viewModel));
        }
示例#4
0
        public async Task <IActionResult> GetTournament([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var viewModel = new TournamentViewModel();

            var tournament = await _context.Tournaments
                             .Include(t => t.Competitors)
                             .Include(t => t.Rounds)
                             .ThenInclude(r => r.Matches)
                             .SingleOrDefaultAsync(t => t.Id == id);

            tournament.Rounds = tournament.Rounds.OrderBy(r => r.RoundNumber).ToList();
            for (var i = 0; i < tournament.Rounds.Count; i++)
            {
                tournament.Rounds[i].Matches = tournament.Rounds[i].Matches.OrderBy(m => m.MatchNumber).ToList();
            }

            if (tournament == null)
            {
                return(NotFound());
            }

            return(Ok(tournament));
        }
        public ActionResult Index(string query = null)
        {
            var upcomingTournaments = _unitOfWork.Tournaments.GetUpcomingTournaments();

            if (!string.IsNullOrEmpty(query))
            {
                upcomingTournaments = upcomingTournaments
                                      .Where(t =>
                                             t.Title.Contains(query) ||
                                             t.Host.Name.Contains(query) ||
                                             t.Game.Title.Contains(query));
            }

            var userId         = User.Identity.GetUserId();
            var participations = _unitOfWork.Participations.GetFutureParticipations(userId)
                                 .ToLookup(p => p.TournamentId);

            var viewModel = new TournamentViewModel
            {
                UpcomingTournaments = upcomingTournaments,
                ShowActions         = User.Identity.IsAuthenticated,
                Heading             = "Upcoming Tournaments",
                SearchTerm          = query,
                Participations      = participations
            };

            return(View("Tournaments", viewModel));
        }
示例#6
0
        public async Task <IActionResult> Create(TournamentViewModel model)
        {
            if (ModelState.IsValid)
            {
                string path = string.Empty;
                model.Groups = new List <GroupEntity>
                {
                };
                model.DateNames = new List <DateNameEntity>
                {
                };


                if (model.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.LogoFile, "Tournaments");
                }
                model.LogoPath = path;
                var tournament = _converterHelper.ToTournamentEntity(model, path, true);
                _context.Add(tournament);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
示例#7
0
        public ActionResult Index()
        {
            TournamentViewModel tournaments = new TournamentViewModel();

            tournaments.Tournaments = GetAll();
            return(View(tournaments));
        }
        /// <summary>
        /// Create tournament action (GET)
        /// </summary>
        /// <returns>View to create a tournament</returns>
        public ActionResult Create()
        {
            var now = TimeProvider.Current.DateTimeNow;

            var tournamentViewModel = new TournamentViewModel {
                Season = (short)now.Year,
                ApplyingPeriodStart = now.AddDays(DAYS_TO_APPLYING_PERIOD_START),
                ApplyingPeriodEnd   = now.AddDays(DAYS_TO_APPLYING_PERIOD_START
                                                  + DAYS_FOR_APPLYING_PERIOD),
                GamesStart = now.AddDays(DAYS_TO_APPLYING_PERIOD_START
                                         + DAYS_FOR_APPLYING_PERIOD
                                         + DAYS_FROM_APPLYING_PERIOD_END_TO_GAMES_START),
                GamesEnd = now.AddDays(DAYS_TO_APPLYING_PERIOD_START
                                       + DAYS_FOR_APPLYING_PERIOD
                                       + DAYS_FROM_APPLYING_PERIOD_END_TO_GAMES_START
                                       + DAYS_FOR_GAMES_PERIOD),
                TransferStart = now.AddDays(DAYS_TO_APPLYING_PERIOD_START
                                            + DAYS_FOR_APPLYING_PERIOD
                                            + DAYS_FROM_APPLYING_PERIOD_END_TO_GAMES_START
                                            + DAYS_FROM_GAMES_START_TO_TRANSFER_START),
                TransferEnd = now.AddDays(DAYS_TO_APPLYING_PERIOD_START
                                          + DAYS_FOR_APPLYING_PERIOD
                                          + DAYS_FROM_APPLYING_PERIOD_END_TO_GAMES_START
                                          + DAYS_FROM_GAMES_START_TO_TRANSFER_START
                                          + DAYS_FOR_TRANSFER_PERIOD)
            };

            return(View(tournamentViewModel));
        }
示例#9
0
        // GET: TournamentTable/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var tournament = _context.Tournaments
                             .Include(t => t.Teams)
                             .Include(t => t.Games)
                             .SingleOrDefault(t => t.Id == id);

            var teamStatistics = _context.Statistics.Where(s => s.TournamentTableId == tournament.Id).OrderByDescending(s => s.Points).ToList();

            if (tournament == null)
            {
                return(HttpNotFound());
            }

            if (teamStatistics == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
            }

            var viewModel = new TournamentViewModel
            {
                TournamentTable = tournament,
                TeamStatistics  = teamStatistics
            };

            return(View(viewModel));
        }
        public IActionResult RemoveWinnable(TournamentViewModel movie, string button)
        {
            ModelState.Clear();
            movie.Winnables.RemoveAt(int.Parse(button));

            return(View("Edit", movie));
        }
示例#11
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Tournament _tournament = tournamentService.GetById((int)id);

            if (_tournament == null)
            {
                return(HttpNotFound());
            }
            if (_tournament.Organizer != User.Identity.Name)
            {
                return(RedirectToAction("Details", new { id = _tournament.Id }));
            }

            var _tournamentViewModel = new TournamentViewModel()
            {
                Tournament     = _tournament,
                CountryList    = GetCountryList(),
                SportGroupList = GetSportGroupList()
            };

            return(View(_tournamentViewModel));
        }
示例#12
0
        public void Map_TournamentAsParam_MappedToViewModel()
        {
            // Arrange
            var tournament = new TournamentBuilder()
                             .WithId(1)
                             .WithName("test")
                             .WithDescription("Volley")
                             .WithLocation("Lviv")
                             .WithScheme(TournamentSchemeEnum.Two)
                             .WithSeason(2016)
                             .WithRegulationsLink("volley.dp.ua")
                             .Build();
            var expected = new TournamentMvcViewModelBuilder()
                           .WithId(1)
                           .WithName("test")
                           .WithDescription("Volley")
                           .WithLocation("Lviv")
                           .WithScheme(TournamentSchemeEnum.Two)
                           .WithSeason(2016)
                           .WithRegulationsLink("volley.dp.ua")
                           .Build();

            // Act
            var actual = TournamentViewModel.Map(tournament);

            // Assert
            TournamentViewModelComparer.AssertAreEqual(expected, actual);
        }
        public IActionResult AddWinnable(TournamentViewModel movie)
        {
            ModelState.Clear();
            movie.Winnables.Add(new TournamentWinnableViewModel());

            return(View("Edit", movie));
        }
        public async Task <IActionResult> Edit(int id, TournamentViewModel movie, string button)
        {
            if (button == "Cancel")
            {
                return(RedirectToAction(nameof(Index)));
            }

            if (id != movie.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var tournament = _mapper.Map <Core.Models.TournamentModel>(movie);
                int i          = 0;
                foreach (var market in tournament.Markets)
                {
                    market.Position = i++;
                }

                await _tournamentService.Update(tournament);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
示例#15
0
        public ActionResult Tournament(int?id)
        {
            if (id == null)
            {
                throw new HttpException(404, "Page not Found");
            }

            try
            {
                Tournament          found = db.Tournaments.Find(id);
                TournamentViewModel tour  = new TournamentViewModel(found, HttpContext.GetOwinContext().Get <ApplicationUserManager>().FindById(db.Events.Find(found.EventID).OrganizerID).UserName);

                if (tour == null)
                {
                    throw new HttpException(404, "Page not Found");
                }
                if ((tour.Public == true) || (Request.IsAuthenticated && (User.Identity.GetUserId() == db.Events.Find(found.EventID).OrganizerID)))
                {
                    ViewBag.Access = true;
                }
                else
                {
                    ViewBag.Access = false;
                }
                return(View(tour));
            }
            catch
            {
                throw new HttpException(404, "Page not Found");
            }
        }
示例#16
0
 internal void SetStorageLocator(TournamentPersistence storageLocator)
 {
     try
     {
         ViewModel = new TournamentViewModel(storageLocator);
     }
     catch (InvalidPlayerListException e)
     {
         MessageBox.Show(string.Format("{0}\r\nSee README.rtf to help diagnose the error", e.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         Application.Current.Shutdown();
         return;
     }
     catch (InvalidRoundException e)
     {
         MessageBox.Show(string.Format("{0}\r\nDelete the file or correct it", e.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         Application.Current.Shutdown();
         return;
     }
     catch (Exception e)
     {
         // For better diagnostics
         MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         throw;
     }
     Title       = string.Format("{0} - {1} {2}", storageLocator.Name, Constants.TitleBarText, Constants.VersionText());
     DataContext = ViewModel;
 }
        /// <summary>
        /// Get finished tournaments
        /// </summary>
        /// <returns>Json result</returns>
        public JsonResult GetFinished()
        {
            var result = _tournamentService.GetFinished()
                         .Select(t => TournamentViewModel.Map(t));

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Tournament tournament = _context.GetTournamentByID(id);

            if (tournament == null)
            {
                return(NotFound());
            }
            var tournaments = _context.GetAllTournaments();
            var games       = _context.GetAllGames().ToList();
            var formats     = _formatContext.GetAllFormats().ToList();
            TournamentViewModel viewModel = new TournamentViewModel
            {
                Tournament = tournament,
                Games      = games,
                Formats    = formats,
            };

            return(View(viewModel));
        }
        public IActionResult Create([FromBody] TournamentViewModel tournamentvm)
        {
            if (!ModelState.IsValid || tournamentvm == null)
            {
                return(BadRequest(ModelState));
            }
            Tournament _newtournament = _mapper.Map <TournamentViewModel, Tournament>(tournamentvm);


            Tournament _newCreatedTournament = _tournamentRepository.CreateTournament(_newtournament);

            _tournamentRepository.Commit();

            if (_newCreatedTournament == null)
            {
                Log.Information("Error Inserting Tournament {@tournamentvm} Into database", tournamentvm);
                return(NotFound(new ResultVM()
                {
                    Status = Status.Error, Message = "An Error Occuered Could not create Tournament " + tournamentvm.tournament_name, Data = tournamentvm
                }));
            }

            tournamentvm = _mapper.Map <Tournament, TournamentViewModel>(_newCreatedTournament);
            Log.Information("Tournament {@tournamentvm} Inserted from database", tournamentvm);
            return(new OkObjectResult(new ResultVM()
            {
                Status = Status.Success, Message = "Succesfully Created Tournament: " + tournamentvm.tournament_name, Data = tournamentvm
            }));
        }
示例#20
0
        public async Task <IActionResult> Create(TournamentViewModel tournamentViewModel)
        {
            if (ModelState.IsValid)
            {
                string path = string.Empty;

                if (tournamentViewModel.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(tournamentViewModel.LogoFile, "Tournaments");
                }

                TournamentEntity tournamentEntity = _converterHelper.ToTournamentEntity(tournamentViewModel, path, true);
                _context.Add(tournamentEntity);

                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, $"Already exists the team {tournamentEntity.Name}.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }

            return(View(tournamentViewModel));
        }
        //Tournaments/Edit/Id
        public ActionResult Edit(string Id)
        {
            //var userId = User.Identity.GetUserId();
            var userId = "3f310a65-509d-43a2-8714-c7626992c3d8";

            //var tournamentInDb = _context.Tournaments.Single(t => t.Id == Id && t.CreatorId == userId);
            var tournamentInDb = _unitOfWork.Tournaments.GetTournamentWithAll(Id);

            if (tournamentInDb == null)
            {
                return(HttpNotFound());
            }

            if (tournamentInDb.CreatorId != userId)
            {
                return(new HttpUnauthorizedResult());
            }

            //var playersInDb = _context.Players.Where(p => p.TournamentId == tournamentInDb.Id).Include(c => c.Team).ToList();

            var viewModel = new TournamentViewModel
            {
                Title            = "Edit Tournament",
                Id               = tournamentInDb.Id,
                Name             = tournamentInDb.Name,
                NumberOfPlayers  = tournamentInDb.NumberOfPlayers,
                TournamentTypeId = tournamentInDb.TournamentTypeId,
                TournamentTypes  = _unitOfWork.TournamentTypes.GetAll(),
                Players          = tournamentInDb.Players
            };

            return(View("TournamentForm", viewModel));
        }
示例#22
0
        public ActionResult Edit(int id)
        {
            var viewModal = new TournamentViewModel();

            viewModal.Tournament = _context.Tournaments.SingleOrDefault(c => c.Id == id);

            return(View("CreateEditTournament", viewModal));
        }
示例#23
0
        public void TournamentsViewModel_Null()
        {
            //Act
            var viewModel = new TournamentViewModel(null);

            //Assert
            viewModel.Tournaments.Should().BeNull();
        }
示例#24
0
        public TournamentViewTest()
        {
            var _client            = new FirebaseClient("https://xamarinfirebase-4a90e.firebaseio.com/");
            var _tournamentService = new TournamentService(new TournamentRepository(_client, "UUID"), new TournamentDetailRepository(_client));

            TournamentViewModel    = new TournamentViewModel(_tournamentService);
            AddTournamentViewModel = new AddDialogViewModel(_tournamentService);
        }
示例#25
0
        public ActionResult Court(int id)
        {
            var tournament = _context.Tournaments.SingleOrDefault(c => c.Id == id);
            var viewModel  = new TournamentViewModel();

            viewModel.Tournament = tournament;
            return(View(viewModel));
        }
示例#26
0
 public TournamentViewModel TournamentViewModel(string tournamentId)
 {
     tournamentService = tournamentService ?? SetTournamentService();
     if (tournamentViewModel == null || tournamentViewModel.Tournament.Id != tournamentId)
     {
         tournamentViewModel = new TournamentViewModel(tournamentService, tournamentId);
     }
     return(tournamentViewModel);
 }
        public ActionResult Show(Guid id)
        {
            var viewModel = new TournamentViewModel
            {
                Tournament = _getTournamentByIdQuery.Execute(id),
            };

            return View(viewModel);
        }
示例#28
0
        public ActionResult AddCourt(TournamentViewModel viewModel)
        {
            var court = viewModel.Court;

            court.Tournament = _context.Tournaments.SingleOrDefault(c => c.Id == viewModel.Tournament.Id);
            _context.Courts.Add(court);
            _context.SaveChanges();
            return(RedirectToAction("Court", new { id = viewModel.Tournament.Id }));
        }
示例#29
0
 public ActionResult Edit(TournamentViewModel _tournamentViewModel)
 {
     if (ModelState.IsValid)
     {
         tournamentService.Update(_tournamentViewModel.Tournament);
         return(RedirectToAction("Index"));
     }
     return(View(_tournamentViewModel));
 }
示例#30
0
        public ActionResult Create()
        {
            var viewModal = new TournamentViewModel();

            viewModal.Tournament = new Tournament()
            {
                StartDate = DateTime.Today, EndDate = DateTime.Today
            };
            return(View("CreateEditTournament", viewModal));
        }
        // GET: TournamentsController/Create
        public async Task <ActionResult> Create()
        {
            var games = await _gameService.GetAllAsync();

            var tournamentViewModel = new TournamentViewModel {
                GamesSelectList = new SelectList(games, "Id", "Name")
            };

            return(View(tournamentViewModel));
        }
示例#32
0
    public async Task<IEnumerable<OddViewModel>> FetchAllTennisOdds(DateTime date)
    {
      var oddsViewModels = new List<OddViewModel>();
      var missingAlias = new List<MissingTeamPlayerAliasObject>();

      var tournaments = DaysTournaments(date, this.sport);
      var oddsSources =
        this.bookmakerRepository
            .GetActiveOddsSources()
            .ToList();

      //check URL's exist first
      var urlCheck =
        tournaments.SelectMany(t => oddsSources.Where(s => this.bookmakerRepository.GetTournamentCouponUrl(t, s) == null)
                                               .Select(s => new MissingTournamentCouponURLObject() { ExternalSource = s.Source, Tournament = t.TournamentName }))
                   .ToList();

      if (urlCheck.Count() > 0)
        throw new MissingTournamentCouponURLException(urlCheck.ToList(), "Tournament coupons missing");

      foreach (var tournament in tournaments)
      {
        foreach (var source in oddsSources)
        {
          try
          {
            var tournamentViewModel = new TournamentViewModel { TournamentName = tournament.TournamentName, TournamentID = tournament.Id };
            var oddsSourceViewModel = new OddsSourceViewModel { Source = source.Source, SourceID = source.Id };
            oddsViewModels.AddRange(await FetchTennisOddsForTournamentSource(date, tournamentViewModel, oddsSourceViewModel));
          }
          catch (MissingTeamPlayerAliasException mtpaEx)
          {
            missingAlias.AddRange(mtpaEx.MissingAlias);
          }
        }
      }
      if (missingAlias.Count > 0)
        throw new MissingTeamPlayerAliasException(missingAlias, "Missing team or player alias");
      return oddsViewModels;
    }
示例#33
0
 public async Task<IEnumerable<OddViewModel>> FetchTennisOddsForTournamentSource(DateTime date, TournamentViewModel tournament, OddsSourceViewModel oddsSource)
 {
   var urlCheck = 
     this.bookmakerRepository
         .GetTournamentCouponUrl(tournament.TournamentName, oddsSource.Source);
   if (urlCheck == null)
   {
     //will have already been checked for the FetchAllTennisOddsVersion
     var missingURL = new MissingTournamentCouponURLObject 
     { 
       ExternalSource = oddsSource.Source, 
       ExternalSourceID = oddsSource.SourceID,
       Tournament = tournament.TournamentName,
       TournamentID = tournament.TournamentID
     };
     throw new MissingTournamentCouponURLException(new MissingTournamentCouponURLObject[] { missingURL }, "Tournament coupons missing");
   }
   return await FetchCoupons(date, tournament.TournamentName, oddsSource.Source);
 }
示例#34
0
    public IEnumerable<OddViewModel> FetchAllFootballOdds(DateTime date)
    {
      var odds = new List<OddViewModel>();

      var tournaments = DaysTournaments(date, this.sport).ToList();
      var oddsSources = this.bookmakerRepository.GetActiveOddsSources().ToList();

      foreach (var tournament in tournaments)
      {
        foreach (var source in oddsSources)
        {
          var tournamentViewModel = new TournamentViewModel { TournamentName = tournament.TournamentName };
          var oddsSourceViewModel = new OddsSourceViewModel { Source = source.Source };
          odds.AddRange(FetchFootballOddsForTournamentSource(date, tournamentViewModel, oddsSourceViewModel));
        }
      }
      return odds;
    }
示例#35
0
 public IEnumerable<OddViewModel> FetchFootballOddsForTournamentSource(
   DateTime date, TournamentViewModel tournament, OddsSourceViewModel oddsSource)
 {
   return FetchCoupons(date, tournament.TournamentName, oddsSource.Source, this.sport, true, false);
 }
 public async Task<IEnumerable<OddViewModel>> FetchFootballOddsForTournamentSource(
   DateTime date, TournamentViewModel tournament, OddsSourceViewModel oddsSource)
 {
   return await FetchCoupons(date, tournament.TournamentName, oddsSource.Source);
 }