Exemple #1
0
        public IActionResult Create(LeagueCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var leagueExists = this.leaguesService.LeagueExistsByName(model.Name);

            if (leagueExists)
            {
                var errorViewModel = new ErrorViewModel
                {
                    ErrorMessage = string.Format(ErrorMessages.LeagueExistsErrorMessage, model.Name)
                };

                return(this.View(viewName: GlobalConstants.ErrorViewName, model: errorViewModel));
            }

            this.leaguesService.CreateLeague(model.Name.Trim(), model.Description.Trim(), model.StartDate, model.EndDate, model.Town.Trim());

            var routeValues = new { Area = GlobalConstants.EmptyArea };

            return(this.RedirectToAction(actionName: GlobalConstants.PendingActionName,
                                         controllerName: GlobalConstants.LeaguesControllerName,
                                         routeValues: routeValues));
        }
        public IActionResult Create(LeagueCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            League league;

            try
            {
                league = this.mapper.Map <League>(model);
                this.leaguesService.CreateAsync(league);
            }
            catch (DbUpdateException e)
            {
                this.logger.LogError(e.Message);
                return(this.View(model));
            }

            return(this.RedirectToAction("Details", "Leagues", new { area = "", id = league.Id }));
        }