public ActionResult EditTournament(int id, TournamentInputModel model)
        {
            var tournamentToEdit = this.LoadTournament(id);

            if (tournamentToEdit == null)
            {
                //Todo implement notifications
                return(this.RedirectToAction("Tournaments"));
            }

            if (model != null)
            {
                tournamentToEdit.Title       = model.Name;
                tournamentToEdit.StartDate   = model.StartDate;
                tournamentToEdit.EndDate     = model.EndDate;
                tournamentToEdit.Rounds      = model.Rounds;
                tournamentToEdit.CountryID   = this.Db.Countries.Single(c => c.Name == model.Country).ID;
                tournamentToEdit.Description = model.Description;

                this.Db.SaveChanges();
                return(this.RedirectToAction("Tournaments"));
            }

            return(this.View(model));
        }
        public ActionResult EditTournament(int id)
        {
            var tournamentToEdit = this.LoadTournament(id);

            if (tournamentToEdit == null)
            {
                //Todo implement notifications
                return(this.RedirectToAction("Tournaments"));
            }

            var model = new TournamentInputModel
            {
                Name        = tournamentToEdit.Title,
                StartDate   = tournamentToEdit.StartDate,
                EndDate     = tournamentToEdit.EndDate,
                Rounds      = tournamentToEdit.Rounds,
                Country     = tournamentToEdit.Country.Name,
                Description = tournamentToEdit.Description,
                Countries   = new List <SelectListItem>()
            };

            this.FillCountriesInSelectListFromDatabase(model);

            return(this.View(model));
        }
 private void FillCountriesInSelectListFromDatabase(TournamentInputModel model)
 {
     foreach (var country in Db.Countries)
     {
         model.Countries.Add(new SelectListItem()
         {
             Text = country.Name,
         });
     }
 }
        public ActionResult AddTournament()
        {
            var model = new TournamentInputModel()
            {
                Countries = new List <SelectListItem>()
            };

            model.Countries.Add(new SelectListItem()
            {
                Text = "Select country ...", Disabled = true, Selected = true
            });

            this.FillCountriesInSelectListFromDatabase(model);

            return(this.View(model));
        }
        public void AddTournament_ShouldRedirect_WhenTournamentIsPassed()
        {
            // Arrange
            var mockedDbContext     = ContextCreator.CreateMockedApllicationDbContext();
            var mockedLiteDbContext = new Mock <IClubContext>();
            var controller          = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object);

            var model = new TournamentInputModel()
            {
                Name        = "testTest",
                StartDate   = new DateTime(2015, 1, 18),
                EndDate     = new DateTime(2020, 1, 18),
                Rounds      = 3,
                Country     = "Bulgariikata2",
                Description = "TestTestTest"
            };

            // Act & Assert
            controller.WithCallTo(x => x.AddTournament(model))
            .ShouldRedirectTo(x => x.Tournaments);
        }
        public ActionResult ReportTournament(int id)
        {
            var tournamentToReport = this.LoadTournament(id);

            if (tournamentToReport == null)
            {
                return(this.RedirectToAction("Tournaments"));
            }

            var model = new TournamentInputModel
            {
                Name        = tournamentToReport.Title,
                StartDate   = tournamentToReport.StartDate,
                EndDate     = tournamentToReport.EndDate,
                Rounds      = tournamentToReport.Rounds,
                Country     = tournamentToReport.Country.Name,
                Description = tournamentToReport.Description,
            };

            return(new ViewAsPdf(model));
        }
        public ActionResult AddTournament(TournamentInputModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var tournament = new Tournament()
                {
                    Title       = model.Name,
                    StartDate   = model.StartDate,
                    EndDate     = model.EndDate,
                    Rounds      = model.Rounds,
                    CountryID   = this.Db.Countries.Single(c => c.Name == model.Country).ID,
                    Description = model.Description
                };

                this.Db.Tournaments.Add(tournament);
                this.Db.SaveChanges();

                return(this.RedirectToAction("Tournaments"));
            }

            return(this.View(model));
        }
        public ActionResult DeleteTournament(int id)
        {
            var tournamentToDelete = this.LoadTournament(id);

            if (tournamentToDelete == null)
            {
                //Todo implement notifications
                return(this.RedirectToAction("Tournaments"));
            }

            var model = new TournamentInputModel
            {
                Name        = tournamentToDelete.Title,
                StartDate   = tournamentToDelete.StartDate,
                EndDate     = tournamentToDelete.EndDate,
                Rounds      = tournamentToDelete.Rounds,
                Country     = tournamentToDelete.Country.Name,
                Description = tournamentToDelete.Description,
            };

            return(this.View(model));
        }
示例#9
0
        public async Task Update(string id, TournamentInputModel input)
        {
            var tournamentInput = this.mapper.Map <Tournament>(input);

            await this.Update <Tournament>("Tournaments", id, tournamentInput);
        }
示例#10
0
        public async Task <string> Insert(TournamentInputModel input)
        {
            var tournament = this.mapper.Map <Tournament>(input);

            return(await this.Insert <Tournament>("Tournaments", tournament));
        }
示例#11
0
        public async Task <ActionResult> Update([FromRoute] string id, [FromBody] TournamentInputModel input)
        {
            await this.tournamentService.Update(id, input);

            return(Ok());
        }
示例#12
0
        public async Task <ActionResult <string> > Insert([FromBody] TournamentInputModel input)
        {
            var result = await this.tournamentService.Insert(input);

            return(Ok(result));
        }