public async Task <IActionResult> Create(TeamEditModel model)
        {
            if (ModelState.IsValid)
            {
                var team = new Team()
                {
                    Id      = Guid.NewGuid(),
                    Name    = model.Name,
                    SportId = model.SportId
                };
                _context.Teams.Add(team);

                if (!String.IsNullOrEmpty(model.Players))
                {
                    foreach (var playerName in model.Players.Split(",")
                             .Select(p => p.Trim())
                             .Where(t => !String.IsNullOrEmpty(t)))
                    {
                        var player = new Player()
                        {
                            Id     = Guid.NewGuid(),
                            Name   = playerName,
                            TeamId = team.Id
                        };
                        _context.Players.Add(player);
                    }
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { sportId = model.SportId }));
            }
            ViewData["sportId"] = model.SportId;
            return(View(model));
        }
        public IActionResult CreateTeam(TeamEditModel model)
        {
            if (ModelState.IsValid)
            {
                if (TeamRepository.TeamExist(model.name))
                {
                    ViewBag.Exist = "These Team account exist";
                }
                else
                {
                    var m = new Team()
                    {
                        name     = model.name,
                        TeamDate = DateTime.Parse(model.TeamDate)
                    };
                    TeamRepository.Add(m);
                    TeamRepository.Commit();

                    HttpContext.Session.SetString("Success", "Team successfully created");

                    return(RedirectToAction("CreateTeam"));
                }
            }

            return(View());
        }
        public async Task <IActionResult> TeamsEdit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            var zespol = await _s16693context.Zespol
                         .Include(z => z.PracownikZespol)
                         .ThenInclude(p => p.IdPracownikNavigation).AsNoTracking()
                         .SingleOrDefaultAsync(z => z.IdZespol == id);

            if (zespol == null)
            {
                return(NotFound());
            }

            var allpracownik = await _s16693context.Pracownik
                               .Include(o => o.IdPracownikNavigation)
                               .Select(x => new CheckBoxItem()
            {
                Id        = x.IdPracownik,
                Nazwa     = x.IdPracownikNavigation.AdresEmail,
                IsChecked = x.PracownikZespol.Any(x => x.IdZespol == zespol.IdZespol) ? true : false
            }).ToListAsync();

            var tEM = new TeamEditModel()
            {
                zespol     = zespol,
                pracowniks = allpracownik,
            };

            return(View(tEM));
        }
Exemple #4
0
        public async Task <IActionResult> EditTeam(CancellationToken cancellationToken)
        {
            var sessionModel = await GetModelFromSession(cancellationToken);

            if (!sessionModel.IsFromSession)
            {
                return(RedirectToAction(nameof(SelectTeam), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }));
            }
            ViewData["TournamentName"] = sessionModel.TournamentName;

            if (sessionModel.Team.IsNew)
            {
                sessionModel.Team             = GetTeamEditorComponentModel(new TeamEntity());
                sessionModel.TeamIsSet        = false;
                sessionModel.TeamInRoundIsSet = false;
            }

            var teamEntity = new TeamEntity();

            // Team.IsNew and Team.Id were set in step "select team"
            if (!sessionModel.Team.IsNew && !sessionModel.TeamIsSet)
            {
                teamEntity = await _appDb.TeamRepository.GetTeamEntityAsync(
                    new PredicateExpression(TeamFields.Id == sessionModel.Team.Id),
                    cancellationToken);

                if (teamEntity == null)
                {
                    return(RedirectToAction(nameof(SelectTeam), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }));
                }
                sessionModel.Team.MapEntityToFormFields(teamEntity);
            }

            if (!teamEntity.IsNew)
            {
                if (!(await _authorizationService.AuthorizeAsync(User, new TeamEntity(teamEntity.Id),
                                                                 Authorization.TeamOperations.SignUpForSeason)).Succeeded)
                {
                    return(RedirectToAction(nameof(Error.AccessDenied), nameof(Error),
                                            new { ReturnUrl = Url.Action(nameof(EditTeam), nameof(TeamApplication), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }) }));
                }
            }

            var teamEditModel = new TeamEditModel
            {
                Round = await GetRoundSelectorComponentModel(teamEntity, cancellationToken),
                Team  = GetTeamEditorComponentModel(teamEntity)
            };

            if (sessionModel.TeamInRoundIsSet)
            {
                teamEditModel.Round.SelectedRoundId = sessionModel.TeamInRound.RoundId;
            }
            if (sessionModel.TeamIsSet)
            {
                teamEditModel.Team = sessionModel.Team;
            }

            return(View(ViewNames.TeamApplication.EditTeam, teamEditModel));
        }
 public ActionResult Create()
 {
     var model = new TeamEditModel
     {
         AllUsers = MembershipService.GetAllUsers().ToArray(),
         SelectedUsers = new UserModel[] { }
     };
     return View(model);
 }
Exemple #6
0
 private TeamModel ConvertTeamDetailModel(TeamEditModel model)
 {
     return(new TeamModel
     {
         Id = model.Id,
         Name = model.Name,
         Description = model.Description,
         Members = model.PostedSelectedUsers == null ? new UserModel[0] : model.PostedSelectedUsers.Select(x => MembershipService.GetUserModel(x)).ToArray(),
     });
 }
Exemple #7
0
 public ActionResult Edit(TeamEditModel model)
 {
     if (ModelState.IsValid)
     {
         TeamRepository.Update(ConvertTeamDetailModel(model));
         ViewBag.UpdateSuccess = true;
     }
     model = ConvertEditTeamModel(TeamRepository.GetTeam(model.Id));
     return(View(model));
 }
Exemple #8
0
        public ActionResult Create()
        {
            var model = new TeamEditModel
            {
                AllUsers      = MembershipService.GetAllUsers().ToArray(),
                SelectedUsers = new UserModel[] { }
            };

            return(View(model));
        }
 public ActionResult Edit(TeamEditModel model)
 {           
     if (ModelState.IsValid)
     {
         TeamRepository.Update(ConvertTeamDetailModel(model));
         ViewBag.UpdateSuccess = true;
     }
     model = ConvertEditTeamModel(TeamRepository.GetTeam(model.Id));
     return View(model);
 }
Exemple #10
0
 public ActionResult Delete(TeamEditModel model)
 {
     if (model != null && model.Id != null)
     {
         TeamModel team = TeamRepository.GetTeam(model.Id);
         TeamRepository.Delete(team.Id);
         TempData["DeleteSuccess"] = true;
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Delete(TeamEditModel model)
 {
     if (model != null && model.Id != null)
     {
         TeamModel team = TeamRepository.GetTeam(model.Id);
         TeamRepository.Delete(team.Id);
         TempData["DeleteSuccess"] = true;
         return RedirectToAction("Index");
     }
     return RedirectToAction("Index");
 }
Exemple #12
0
        private TeamEditModel GetEditData(int id)
        {
            var model = new TeamEditModel
            {
                Command = _editTeamQuery.Handle(new GetTeamEditQuery()
                {
                    Id = id
                }),
            };

            return(model);
        }
Exemple #13
0
        public bool Edit(TeamEditModel model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Teams
                    .Single(e => e.TeamId == model.TeamId);     // && e.OwnerId == _userId

                entity.Name = model.Name;
                return(ctx.SaveChanges() == 1);
            }
        }
Exemple #14
0
        public ActionResult Edit(Guid Id)
        {
            if (Request.IsLocal)
            {
                TempData["ReturnUrl"] = Request.UrlReferrer;
            }
            Team Team = reposetory.GetTeam(Id);

            if (Team == null)
            {
                return(HttpNotFound());
            }
            int minTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMin"]);
            int maxTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMax"]);

            var Active = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID).Select(d => new SelectListItem {
                Value = d.Person.PersonID.ToString(), Text = d.Person.FullName
            }).ToList();

            Active.Insert(0, new SelectListItem {
                Value = Guid.Empty.ToString(), Text = General.DropDownChoose
            });
            TeamEditModel Model = new TeamEditModel
            {
                Team           = Team,
                Active         = Active,
                TeamLeader     = Team.TeamLeaderId,
                Teammembers    = new List <Guid>(),
                minTeammembers = minTeammembers,
                maxTeammembers = maxTeammembers
            };

            foreach (Person P in Team.Teammembers ?? new List <Person>())
            {
                if (P.PersonID != Team.TeamLeaderId)
                {
                    Model.Teammembers.Add(P.PersonID);
                }
            }
            int EmptyAdd = maxTeammembers - Model.Teammembers.Count - 1; // (Team.Trial ? 2 : 1);

            for (var i = 0; i < EmptyAdd; i++)
            {
                Model.Teammembers.Add(Guid.Empty);
            }


            return(View(Model));
        }
        public IActionResult EditTeam(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("400"));
            }
            var           kp = TeamRepository.Get(id);
            TeamEditModel po = new TeamEditModel()
            {
                name = kp.name,
                Date = kp.TeamDate.ToShortDateString(),
                Time = kp.TeamDate.ToShortTimeString()
            };

            return(View(po));
        }
        public IHttpActionResult Put(TeamEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = LocalTeamService();

            if (!service.Edit(model))
            {
                return(InternalServerError());
            }

            return(Ok(model));
        }
        public IActionResult EditTeam(TeamEditModel model, int id)
        {
            if (ModelState.IsValid)
            {
                var jp = new Team()
                {
                    Id       = id,
                    name     = model.name,
                    TeamDate = DateTime.Parse(model.TeamDate)
                };
                TeamRepository.Update(jp);
                TeamRepository.Commit();
                return(RedirectToAction("ViewTeam"));
            }

            return(View());
        }
        public ActionResult Create(TeamEditModel model)
        {
            while (!String.IsNullOrEmpty(model.Name) && model.Name.Last() == ' ')
            {
                model.Name = model.Name.Substring(0, model.Name.Length - 1);
            }

            if (ModelState.IsValid)
            {
                if (TeamRepository.Create(ConvertTeamDetailModel(model)))
                {
                    TempData["CreateSuccess"] = true;
                    return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelError("", Resources.Team_Create_Failure);
                }
            }

            return View(model);
        }
        public ActionResult Create(TeamEditModel model)
        {
            while (!String.IsNullOrEmpty(model.Name) && model.Name.Last() == ' ')
            {
                model.Name = model.Name.Substring(0, model.Name.Length - 1);
            }

            if (ModelState.IsValid)
            {
                if (TeamRepository.Create(ConvertTeamDetailModel(model)))
                {
                    TempData["CreateSuccess"] = true;
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", Resources.Team_Create_Failure);
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> Edit(Guid?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var team = await _context.Teams.FindAsync(id);

            if (team == null)
            {
                return(NotFound());
            }

            var model = new TeamEditModel()
            {
                Id      = team.Id,
                Name    = team.Name,
                SportId = team.SportId
            };

            return(View(model));
        }
Exemple #21
0
        public async Task <IActionResult> Edit(long teamId, CancellationToken cancellationToken)
        {
            var team = await _appDb.TeamRepository.GetTeamEntityAsync(new PredicateExpression(TeamFields.Id == teamId), cancellationToken);

            if (team == null)
            {
                return(NotFound());
            }

            if (!(await _authorizationService.AuthorizeAsync(User, new TeamEntity(team.Id),
                                                             Authorization.TeamOperations.EditTeam)).Succeeded)
            {
                return(JsonAjaxRedirectForModal(Url.Action(nameof(Error.AccessDenied), nameof(Error),
                                                           new { ReturnUrl = Url.Action(nameof(MyTeam), nameof(Team), new { Organization = _siteContext.UrlSegmentValue }) })));
            }

            var model = new TeamEditModel
            {
                Round = await GetRoundSelectorComponentModel(team, cancellationToken),
                Team  = GetTeamEditorComponentModel(team)
            };

            return(PartialView(ViewNames.Team._EditTeamModalPartial, model));
        }
        public async Task <IActionResult> Edit(Guid?id, TeamEditModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var team = await _context.Teams.FindAsync(id);

                if (team == null)
                {
                    return(NotFound());
                }

                team.Name = model.Name;

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { sportId = model.SportId }));
            }
            return(View(model));
        }
 public bool Edit(TeamEditModel model)
 {
     throw new NotImplementedException();
 }
Exemple #24
0
        public ActionResult Edit(TeamEditModel response)
        {
            if (response.Team == null || response.Team.TeamID == Guid.Empty)
            {
                return(HttpNotFound());
            }

            Team Team = reposetory.GetTeam(response.Team.TeamID);

            if (Team == null)
            {
                return(HttpNotFound());
            }
            int minTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMin"]);
            int maxTeammembers = int.Parse(ConfigurationManager.AppSettings["TeamMax"]);

            if (response.Start <Team.Folder.Start | response.Start> Team.Folder.Finish)
            {
                ModelState.AddModelError("Team.Start", General.ErrorStartNotWithinFolderDate);
                ModelState.SetModelValue("Team.Start", new ValueProviderResult(Team.Start, Team.Start.ToString(), CultureInfo.InvariantCulture));
            }
            if (response.Team.Trial && response.Teammembers != null && response.Teammembers.Where(x => x != Guid.Empty).Count() >= maxTeammembers - 1)
            {
                ModelState.AddModelError("", General.ErrorTrialToManyTeammembers);
            }

            if (ModelState.IsValid)
            {
                Team.Start = response.Start;
                //Team.Duration = response.Team.Duration;
                //Team.Location = response.Team.Location;
                Team.Note         = response.Team.Note;
                Team.Star         = response.Team.Star;
                Team.Status       = response.Team.Status;
                Team.Trial        = response.Team.Trial;
                Team.TrialInfo    = response.Team.TrialInfo;
                Team.TeamLeaderId = response.TeamLeader;

                Team.Teammembers = new List <Person>();
                if (response.Teammembers != null)
                {
                    foreach (Guid p in response.Teammembers.Where(x => x != Guid.Empty).Distinct())
                    {
                        Person dbP = reposetory.GetPerson(p);
                        if (dbP != null && Team.Teammembers.Count() < maxTeammembers)
                        {
                            Team.Teammembers.Add(dbP);
                        }
                    }
                }
                Person TeamLeader = reposetory.GetPerson(Team.TeamLeaderId);
                if (TeamLeader != null)
                {
                    Team.Teammembers.Add(TeamLeader);
                }
                if (reposetory.SaveTeam(Team))
                {
                    ViewBag.FormSucces = true;
                    ModelState.Clear();
                    Notification not = reposetory.Notify(Team, String.Format(Notifications.TeamChanged));
                    reposetory.NotifyAddPlanner(not, Team.Association.AssociationID);
                    reposetory.NotifyAddTeam(not, Team);
                    reposetory.NotifySave(not);
                    //if (TempData["ReturnUrl"] != null) return Redirect(((Uri)TempData["ReturnUrl"]).ToString());
                }
            }

            var Active = reposetory.GetAssociationActivePersons(CurrentProfile.AssociationID).Select(d => new SelectListItem {
                Value = d.Person.PersonID.ToString(), Text = d.Person.FullName
            }).ToList();

            Active.Insert(0, new SelectListItem {
                Value = Guid.Empty.ToString(), Text = General.DropDownChoose
            });
            response.Teammembers = response.Teammembers == null ? new List <Guid>() : response.Teammembers = response.Teammembers.Where(x => x != Guid.Empty).Distinct().ToList();
            int EmptyAdd = maxTeammembers - response.Teammembers.Count - 1; // (response.Team.Trial ? 2 : 1);

            for (var i = 0; i < EmptyAdd; i++)
            {
                response.Teammembers.Add(Guid.Empty);
            }
            response.Team           = Team;
            response.Active         = Active;
            response.minTeammembers = minTeammembers;
            response.maxTeammembers = maxTeammembers;

            return(View(response));
        }
 private TeamModel ConvertTeamDetailModel(TeamEditModel model)
 {
     return new TeamModel
     {
         Id = model.Id,
         Name = model.Name,
         Description = model.Description,
         Members = model.PostedSelectedUsers == null ? new UserModel[0] : model.PostedSelectedUsers.Select(x => MembershipService.GetUserModel(x)).ToArray(),
     };
 }
Exemple #26
0
        public async Task <IActionResult> Edit([FromForm] TeamEditModel model, CancellationToken cancellationToken)
        {
            TeamEntity team = null;

            if (model.Team != null && !model.Team.IsNew)
            {
                team = await _appDb.TeamRepository.GetTeamEntityAsync(new PredicateExpression(TeamFields.Id == model.Team.Id), cancellationToken);

                if (team == null)
                {
                    return(NotFound());
                }

                if (!(await _authorizationService.AuthorizeAsync(User, new TeamEntity(team.Id),
                                                                 Authorization.TeamOperations.EditTeam)).Succeeded)
                {
                    return(JsonAjaxRedirectForModal(Url.Action(nameof(Error.AccessDenied), nameof(Error),
                                                               new { ReturnUrl = Url.Action(nameof(MyTeam), nameof(Team), new { Organization = _siteContext.UrlSegmentValue }) })));
                }

                team.TeamInRounds.AddRange(await _appDb.TeamInRoundRepository.GetTeamInRoundAsync(
                                               new PredicateExpression(RoundFields.TournamentId == _siteContext.TeamTournamentId & TeamInRoundFields.TeamId == team.Id),
                                               cancellationToken));

                if (team.TeamInRounds.Count > 1)
                {
                    _logger.LogError("Teams ID {0} belongs to {1} rounds for tournament ID {2}", team.Id,
                                     team.TeamInRounds.Count, _siteContext.TeamTournamentId);
                }
            }

            team ??= new TeamEntity();

            model.TeamEntity = team;
            model.Round      = await GetRoundSelectorComponentModel(team, cancellationToken);

            model.Team = GetTeamEditorComponentModel(team);
            // sync input with new model instance
            if (!await TryUpdateModelAsync(model))
            {
                return(PartialView(ViewNames.Team._EditTeamModalPartial, model));
            }

            model.MapFormFieldsToEntity();
            ModelState.Clear();

            if (!await model.ValidateAsync(new TeamValidator(model.TeamEntity, _siteContext), _siteContext.TeamTournamentId, ModelState, cancellationToken))
            {
                return(PartialView(ViewNames.Team._EditTeamModalPartial, model));
            }

            try
            {
                if (await _appDb.GenericRepository.SaveEntityAsync(model.TeamEntity, false, true, cancellationToken))
                {
                    TempData.Put <MyTeamMessageModel.MyTeamMessage>(nameof(MyTeamMessageModel.MyTeamMessage), new MyTeamMessageModel.MyTeamMessage {
                        AlertType = SiteAlertTagHelper.AlertType.Success, MessageId = MyTeamMessageModel.MessageId.TeamDataSuccess
                    });
                    return(JsonAjaxRedirectForModal(Url.Action(nameof(MyTeam), nameof(Team), new { Organization = _siteContext.UrlSegmentValue, id = team.Id })));
                }
            }
            catch (Exception e)
            {
                TempData.Put <MyTeamMessageModel.MyTeamMessage>(nameof(MyTeamMessageModel.MyTeamMessage), new MyTeamMessageModel.MyTeamMessage {
                    AlertType = SiteAlertTagHelper.AlertType.Danger, MessageId = MyTeamMessageModel.MessageId.TeamDataFailure
                });
                _logger.LogCritical(e, "Error saving team id '{0}'", model.Team.IsNew ? "new" : model.Team.Id.ToString());
                return(JsonAjaxRedirectForModal(Url.Action(nameof(MyTeam), new { Organization = _siteContext.UrlSegmentValue, id = team.Id })));
            }

            // We never should come this far
            return(PartialView(ViewNames.Team._EditTeamModalPartial, model));
        }
        public async Task <IActionResult> TeamsEdit(TeamEditModel tEM)
        {
            if (ModelState.IsValid)
            {
                _s16693context.Update(tEM.zespol);
                List <PracownikZespol> pracowniklist = new List <PracownikZespol>();

                foreach (var item in tEM.pracowniks)
                {
                    if (item.IsChecked == true)
                    {
                        var PZ = new PracownikZespol()
                        {
                            IdPracownik = item.Id,
                            IdZespol    = (int)tEM.zespol.IdZespol,
                            DataPrzypisaniaPracownika = DateTime.Now
                        };
                        _s16693context.Add(PZ);
                    }
                }

                var dt = await _s16693context.PracownikZespol.Where(x => x.IdZespol == tEM.zespol.IdZespol).ToListAsync();

                foreach (var item in dt)
                {
                    _s16693context.PracownikZespol.Remove(item);
                    await _s16693context.SaveChangesAsync();
                }

                var idS = await _s16693context.PracownikZespol.Where(x => x.IdZespol == tEM.zespol.IdZespol).ToListAsync();

                foreach (var item in pracowniklist)
                {
                    if (idS.Contains(item))
                    {
                        _s16693context.PracownikZespol.Add(item);
                        await _s16693context.SaveChangesAsync();
                    }
                }
                await _s16693context.SaveChangesAsync();

                return(RedirectToAction(nameof(Teams)));
            }

            else if (!ModelState.IsValid)
            {
                var allpracownik = await _s16693context.Pracownik
                                   .Include(o => o.IdPracownikNavigation)
                                   .Select(x => new CheckBoxItem()
                {
                    Id        = x.IdPracownik,
                    Nazwa     = x.IdPracownikNavigation.AdresEmail,
                    IsChecked = x.PracownikZespol.Any(x => x.IdZespol == tEM.zespol.IdZespol) ? true : false
                }).ToListAsync();

                var newTEM = new TeamEditModel()
                {
                    zespol     = tEM.zespol,
                    pracowniks = allpracownik,
                };

                return(View("TeamsEdit", newTEM));
            }
            return(View(tEM));
        }
Exemple #28
0
        public async Task <IActionResult> EditTeam([FromForm] TeamEditModel teamEditModel, CancellationToken cancellationToken)
        {
            var sessionModel = await GetModelFromSession(cancellationToken);

            if (!sessionModel.IsFromSession)
            {
                return(RedirectToAction(nameof(SelectTeam), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }));
            }
            ViewData["TournamentName"] = sessionModel.TournamentName;

            TeamEntity teamEntity = null;

            if (teamEditModel.Team != null && !teamEditModel.Team.IsNew)
            {
                teamEntity = await _appDb.TeamRepository.GetTeamEntityAsync(new PredicateExpression(TeamFields.Id == teamEditModel.Team.Id), cancellationToken);

                if (teamEntity == null)
                {
                    return(RedirectToAction(nameof(SelectTeam), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }));
                }

                if (!(await _authorizationService.AuthorizeAsync(User, new TeamEntity(teamEntity.Id),
                                                                 Authorization.TeamOperations.SignUpForSeason)).Succeeded)
                {
                    return(RedirectToAction(nameof(Error.AccessDenied), nameof(Error),
                                            new { ReturnUrl = Url.Action(nameof(EditTeam), nameof(TeamApplication), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }) }));
                }

                teamEntity.TeamInRounds.AddRange(await _appDb.TeamInRoundRepository.GetTeamInRoundAsync(
                                                     new PredicateExpression(RoundFields.TournamentId == _tenantContext.TournamentContext.ApplicationTournamentId & TeamInRoundFields.TeamId == teamEntity.Id),
                                                     cancellationToken));

                if (teamEntity.TeamInRounds.Count > 1)
                {
                    _logger.LogError("Teams ID {0} belongs to {1} rounds for tournament ID {2}", teamEntity.Id,
                                     teamEntity.TeamInRounds.Count, _tenantContext.TournamentContext.ApplicationTournamentId);
                }
            }

            teamEntity ??= new TeamEntity();

            teamEditModel.TeamEntity = teamEntity;
            teamEditModel.Round      = await GetRoundSelectorComponentModel(teamEntity, cancellationToken);

            teamEditModel.Team = GetTeamEditorComponentModel(teamEntity);
            // sync input with new model instance
            if (!await TryUpdateModelAsync(teamEditModel))
            {
                return(View(ViewNames.TeamApplication.EditTeam, teamEditModel));
            }

            teamEditModel.MapFormFieldsToEntity();
            ModelState.Clear();

            if (!await teamEditModel.ValidateAsync(new TeamValidator(teamEditModel.TeamEntity, _tenantContext), _tenantContext.TournamentContext.ApplicationTournamentId, ModelState, cancellationToken))
            {
                return(View(ViewNames.TeamApplication.EditTeam, teamEditModel));
            }

            if (teamEntity.TeamInRounds.Any())
            {
                var tir = teamEntity.TeamInRounds.First();
                sessionModel.TeamInRound.MapEntityToFormFields(tir);
                sessionModel.TeamInRoundIsSet = true;
            }

            sessionModel.Team.MapEntityToFormFields(teamEntity);
            sessionModel.TeamIsSet = true;
            SaveModelToSession(sessionModel);

            return(RedirectToAction(nameof(SelectVenue), new { Organization = _tenantContext.SiteContext.UrlSegmentValue }));
        }