示例#1
0
        public async Task <IActionResult> Create(TeamCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            Team team;

            try
            {
                team = this.mapper.Map <Team>(model);

                var file = model.Badge;
                if (file != null)
                {
                    var badgeId    = string.Format(GlobalConstants.BadgePicture, model.Name);
                    var fileStream = file.OpenReadStream();

                    var imageUploadResult = this.cloudinaryService.UploadTeamBadgePicture(badgeId, fileStream);
                    team.BadgeVersion = imageUploadResult.Version;
                }
                await this.teamsService.CreateAsync(team);
            }
            catch (DbUpdateException e)
            {
                this.logger.LogError(e.Message);
                return(this.View(model));
            }

            return(this.RedirectToAction("Details", "Teams", new { area = "", id = team.Id }));
        }
示例#2
0
        public IActionResult Create(TeamCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var currentUser = this.User.Identity.Name;

            var playerHasATeam = this.playersService.PlayerHasATeam(currentUser);

            if (playerHasATeam)
            {
                var errorViewModel = new ErrorViewModel
                {
                    ErrorMessage = string.Format(ErrorMessages.PlayerInTeamErrorMessage, currentUser)
                };

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

            var teamExists = this.teamsService.TeamExistsByName(model.Name);

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

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

            this.teamsService.CreateTeam(model.Name.Trim(), model.Initials.Trim(), currentUser);

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

            return(this.RedirectToAction(controllerName: GlobalConstants.TeamsControllerName,
                                         actionName: GlobalConstants.AllActionName,
                                         routeValues: routeValues));
        }