Exemple #1
0
        private CreateTrialCompetitorViewModel PrepareSelectOptions(CreateTrialCompetitorViewModel viewModel)
        {
            viewModel.RiderOptions = this.mapper.MapCollection <TrialRider, SelectOption>(this.ridersData.GetAll());
            viewModel.HorseOptions = this.mapper.MapCollection <TrialHorse, SelectOption>(this.horsesData.GetAll());
            viewModel.TrialOptions = this.mapper.MapCollection <Trial, SelectOption>(this.trialsData.GetAll());

            return(viewModel);
        }
Exemple #2
0
        public IActionResult Create(CreateTrialCompetitorViewModel viewModel)
        {
            var competitor = this.mapper.Map <TrialCompetitor>(viewModel);

            var(success, field, message) = this.competitorBusiness.Create(competitor);

            if (!success)
            {
                ModelState.AddModelError(field, message);
            }

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

            return(RedirectToAction("Create"));
        }