Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateTeamInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(View(inputModel));
            }

            var teamId = await this.teamService.CreateTeamAsync(inputModel);

            return(this.RedirectToAction(nameof(Details), new { id = teamId }));
        }
        public async Task <IActionResult> Create(CreateTeamInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var teamName = await this.teamsService.CreateAsync(input);

            return(this.RedirectToAction(nameof(this.Details), new { name = teamName.ToLower().Replace(' ', '-') }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(CreateTeamInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            await this.teamsService.CreateAsync(input, userId);

            return(this.Redirect("/"));
        }
Ejemplo n.º 4
0
        public async Task CreateAsync(CreateTeamInputModel input, string userId)
        {
            var team = new Team
            {
                Name        = input.Name,
                Tag         = input.Tag,
                Description = input.Description,
                CaptainId   = userId,
            };

            await this.teamsRepository.AddAsync(team);

            await this.teamsRepository.SaveChangesAsync();
        }
Ejemplo n.º 5
0
        public async Task <string> CreateAsync(CreateTeamInputModel inputModel)
        {
            var country = await this.database.Countries.FirstOrDefaultAsync(c => c.Name.ToLower() == inputModel.CountryName.ToLower());

            if (country == null)
            {
                country = new Country
                {
                    Name = inputModel.CountryName,
                };

                await this.database.Countries.AddAsync(country);
            }

            var town = await this.database.Towns.FirstOrDefaultAsync(t => t.Name.ToLower() == inputModel.TownName.ToLower());

            if (town == null)
            {
                town = new Town
                {
                    Name    = inputModel.TownName,
                    Country = country,
                };

                await this.database.Towns.AddAsync(town);
            }

            var team = await this.database.Teams.FirstOrDefaultAsync(tm => tm.Name.ToLower() == inputModel.Name.ToLower());

            if (team == null)
            {
                team = new Team
                {
                    Name                 = inputModel.Name,
                    LogoUrl              = inputModel.LogoUrl,
                    CoverPhotoUrl        = inputModel.CoverPhotoUrl,
                    CoachName            = inputModel.CoachName,
                    TrainingsDescription = inputModel.TrainingsDescription,
                    ContactUrl           = inputModel.ContactUrl,
                    Town                 = town,
                };

                await this.database.Teams.AddAsync(team);

                await this.database.SaveChangesAsync();
            }

            return(team.Name);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create(CreateTeamInputModel input)
        {
            if (!await this.citiesService.CheckIfCityExistsAsync(input.CityId))
            {
                return(this.NotFound());
            }

            if (!this.servicesService.CheckIfServicesExist(input.Services))
            {
                return(this.NotFound());
            }

            var serviceModel = input.To <TeamServiceModel>();
            var id           = await this.teamsService.CreateAsync(serviceModel);

            return(this.Redirect("/Administration/Teams"));
        }
Ejemplo n.º 7
0
        public ActionResult Create(CreateTeamInputModel model)
        {
            if (model != null && this.ModelState.IsValid)
            {
                var teamToDb = Mapper.Map <Team>(model);
                this.Data.Teams.Add(teamToDb);
                this.Data.SaveChanges();

                foreach (var playerId in model.PlayerIds)
                {
                    if (playerId != 0)
                    {
                        var player = this.Data.Players.Find(playerId);
                        player.TeamId = teamToDb.Id;
                        this.Data.SaveChanges();
                    }
                }

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

            LoadUnemploymentPlayers();
            return(this.View());
        }
        public async Task <int> CreateTeamAsync(CreateTeamInputModel inputModel)
        {
            if (this.DbContext.Teams.Any(t => t.Name == inputModel.Name))
            {
                throw new TeamExistsException();
            }

            var team = this.Mapper.Map <Team>(inputModel);

            team.TeamLogo = string.Format(TeamLogoPath, team.Name);

            try
            {
                await this.DbContext.Teams.AddAsync(team);

                await this.DbContext.SaveChangesAsync();
            }
            catch
            {
                throw new SaveDbChangesException();
            }

            return(team.Id);
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create()
        {
            var cities = await this.citiesService.GetAllAsync <CitySelectModel>();

            var services = await this.servicesService.GetAllAsync <ServiceSelectModel>();

            var model = new CreateTeamInputModel()
            {
                Cities = cities
                         .Select(c => new SelectListItem()
                {
                    Text  = c.Name,
                    Value = c.Id.ToString(),
                }).ToList(),
                AllServices = services
                              .Select(c => new SelectListItem()
                {
                    Text  = c.Name,
                    Value = c.Id.ToString(),
                }).ToList(),
            };

            return(this.View(model));
        }
Ejemplo n.º 10
0
        public ActionResult Create(CreateTeamInputModel model)
        {
            if (model !=null && this.ModelState.IsValid)
            {
                var teamToDb = Mapper.Map<Team>(model);
                this.Data.Teams.Add(teamToDb);
                this.Data.SaveChanges();

                foreach (var playerId in model.PlayerIds)
                {
                    if (playerId != 0)
                    {
                        var player = this.Data.Players.Find(playerId);
                        player.TeamId = teamToDb.Id;
                        this.Data.SaveChanges();
                    }
                }

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

            LoadUnemploymentPlayers();
            return this.View();
        }
Ejemplo n.º 11
0
        public IActionResult Create()
        {
            var viewModel = new CreateTeamInputModel();

            return(this.View(viewModel));
        }