public async Task CreateShouldAddNewTournament()
        {
            const string       databaseName = "TournamentCreate";
            ITournamentService service      = await GetTournamentService(databaseName);

            //Act
            TournamentFormModel expectedModel = new TournamentFormModel()
            {
                Id              = 5,
                Name            = "SandanskiOpen",
                StartDate       = new DateTime(),
                Place           = "Sandanski",
                NumberOfPlayers = 16,
                Type            = Domain.Enums.Tournament.TournamentType.Charity
            };

            await service.Create(expectedModel, new Guid().ToString());

            var db          = new FakeSportDbContext(databaseName);
            var actualModel = db.Data.Tournaments.FirstOrDefault(t => t.Id == 5);

            //Assert
            Assert.True(expectedModel.Id == actualModel.Id);
            Assert.True(expectedModel.Name.Equals(actualModel.Name));
            Assert.True(expectedModel.StartDate == actualModel.StartDate);
            Assert.True(expectedModel.NumberOfPlayers == actualModel.NumberOfPlayers);
            Assert.True(expectedModel.Place.Equals(actualModel.Place));
        }
Exemplo n.º 2
0
        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);
        }
        public IActionResult Post(TournamentDTO dto)
        {
            var input = _mapper.FromDTO(dto);

            var result = _tournamentService.Create(input);

            return(Ok(_mapper.ToDTO(result)));
        }
Exemplo n.º 4
0
        public void Post([FromBody] TournamentViewModel tournament)
        {
            var mapper        = config.CreateMapper();
            var tournamentDto = mapper.Map <TournamentViewModel, TournamentDTO>(tournament);

            tournamentDto.Prizes = mapper.Map <List <PrizeViewModel>, List <PrizeDTO> >(tournament.Prizes);
            var user = userManager.GetUserAsync(User).Result;

            tournamentDto.Initiator = user.UserName;
            tournamentService.Create(tournamentDto);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create(TournamentFormModel model)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            await tournamentService.Create(model, userId);

            return(RedirectToAction(nameof(All)));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> CreateTournament([FromBody] CreateTournamentRequest request)
        {
            try
            {
                await tournamentService.Create(request.Date);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, $"Bad time: {e.Message}"));
            }
        }
        public ActionResult Create(TournamentViewModel tournamentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var tournament = tournamentViewModel.ToDomain();
                    _tournamentService.Create(tournament);
                    return(RedirectToAction("Index"));
                }

                return(View(tournamentViewModel));
            }
            catch (TournamentValidationException e)
            {
                ModelState.AddModelError(e.ValidationKey, e.Message);
                return(View(tournamentViewModel));
            }
        }
Exemplo n.º 8
0
        public async Task <ActionResult> Create(TournamentViewModel _tournamentViewModel)
        {
            if (ModelState.IsValid)
            {
                Tournament      tournament  = tournamentService.Create(_tournamentViewModel.Tournament);
                var             userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                ApplicationUser user        = await userManager.FindByNameAsync(tournament.Organizer);

                string subject = string.Format("Tournament \"{0}\" was successfully created.", tournament.Name);
                string body    = MailTemplateBody.GetBody(user.FullName, String.Format("Congradulation! Your tournament \"{0}\" was successfully created.", tournament.Name));

                await userManager.SendEmailAsync(user.Id, subject, body);

                return(RedirectToAction("Details", "Tournaments", new { id = tournament.Id }));
            }
            _tournamentViewModel.CountryList    = GetCountryList();
            _tournamentViewModel.SportGroupList = GetSportGroupList();

            return(View(_tournamentViewModel));
        }
Exemplo n.º 9
0
        public ActionResult Create(TournamentCreateModel model, params string[] selectedHost)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var modelBL = _mapper.Map <TournamentBL>(model);

            if (selectedHost == null)
            {
                selectedHost = new string[] { }
            }
            ;

            var userId = User.Identity.GetUserId();

            modelBL.HostsId     = $"{userId};{string.Join(";", selectedHost)}";
            modelBL.DateCreated = DateTime.Now;

            _tournamentService.Create(modelBL);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Post([FromBody] string name)
        {
            var tournament = await _tournamentService.Create(name);

            return(Json(tournament.Id));
        }
Exemplo n.º 11
0
        //[Authorize(Roles = PlayerRolesConst.MainPlayer)]
        public async Task <IActionResult> Create(TournamentCreateModel model)
        {
            await _tournamentService.Create(model);

            return(Ok());
        }