Example #1
0
        public async Task <IActionResult> Create(ChampionshipViewModel championshipViewModel)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Data is not valid");
                championshipViewModel.CountriesItems = countryService.GetAllAsKeyValuePairs();

                return(View(championshipViewModel));
            }
            try
            {
                await championshipService.CreateAsync(championshipViewModel);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.InnerException?.Message ?? ex.Message);
                championshipViewModel.CountriesItems = countryService.GetAllAsKeyValuePairs();

                return(View(championshipViewModel));
            }

            TempData["SuccessMessage"] = "Championship added successfully.";

            return(RedirectToAction("Index"));
        }
        public async Task CreateAsync(ChampionshipCreateModel model, CancellationToken cancellationToken = default)
        {
            var championship = _mapper.From(model).AdaptToType <Championship>();

            await _championatService.CreateAsync(championship, cancellationToken);
        }