// GET: TournamentRegistration/Display
        /// <summary>
        /// Displays the registration of an organization for a tournament.
        /// </summary>
        /// <param name="tournamentId">ID of tournament</param>
        /// <returns>Redirect to login, if the user is not logged in.
        /// Redirect to organization selection, if there is no current organization.
        /// Redirect to Home, if the user is not a delegate of the organization.
        /// View to display registration information.</returns>
        public async Task<ActionResult> Display(Guid tournamentId, Guid? organizationId = null, String tab = "")
        {

            #region Checks
            // Get user

            var ident = HttpContext.User.Identity as ClaimsIdentity;
            var userId = ident.GetUserId();
            var user = await userManager.FindByIdAsync(userId);

            Guid currentOrganizationId = Guid.Empty;

            // Get organizationId parameter

            if (organizationId != null)
            {
                currentOrganizationId = (Guid)organizationId;
            }

            // If we do not have an organizationId parameter, get the organizationId from the user object

            if (currentOrganizationId == Guid.Empty)
            {
                var currentOrganizationIdNullable = user.CurrentOrganizationId;
                currentOrganizationId = (Guid)(currentOrganizationIdNullable == null ? Guid.Empty : currentOrganizationIdNullable);
            }

            // If still do not have an organizationId, let the user select an organization

            if (currentOrganizationId == Guid.Empty)
            {
                String returnUrl = null;

                if (HttpContext != null
                    && HttpContext.Request != null)
                {
                    returnUrl = HttpContext.Request.RawUrl;
                }

                return RedirectToAction("Select", "Organization", new { returnUrl = returnUrl });
            }


            // Check user permissions: Either organization delegate or slot manager for tournament

            if (!userManager.HasOrganizationRole(userId, currentOrganizationId, OrganizationRole.Delegate)
                && !userManager.HasTournamentRole(userId, tournamentId, TournamentRole.SlotManager))
            {
                return RedirectToAction("Index", "Home");
            }

            #endregion
            // Everything okay, get the registration

            var registration = tournamentRegistrationsManager.GetRegistration(tournamentId, currentOrganizationId);

            // If we found a registration, build the view model

            if (registration != null)
            {
                TournamentOrganizationRegistrationViewModel viewModel = new TournamentOrganizationRegistrationViewModel
                {
                    Registration = registration,
                    Bookings = bookingManager.GetBookings(registration.OrganizationId, registration.TournamentId)
                };

                #region Teams

                var teams = tournamentRegistrationsManager
                    .GetTeams(registration.TournamentId, registration.OrganizationId)
                    .OrderBy(t => t.Created)
                    .ToList(); ;
                //viewModel.TeamsCompleted = teams.Count();

                // Generate Autosuffix if necessary

                foreach (Team team in teams)
                {
                    if (String.IsNullOrWhiteSpace(team.AutoSuffix))
                    {
                        team.AutoSuffix = tournamentRegistrationsManager.GenerateAutosuffix(registration.OrganizationId, registration.TournamentId, teams);
                        tournamentRegistrationsManager.SetTeam(team, user);
                    }
                }


                // Add teams to view model

                foreach (var team in teams)
                {
                    viewModel.Teams.Add(new APIModels.Team(team));
                }

                // Calculate completed teams

                viewModel.TeamsCompleted = teams.Where(t => t.Speaker.Count >= t.Tournament.TeamSize).Count();

                // if we do not get as many teams as confirmed, add empty teams

                var missingTeams = registration.TeamsPaid - viewModel.Teams.Count;

                for (int i = 0; i < missingTeams; i++)
                {
                    var team = new Team
                    {
                        Id = Guid.NewGuid(),
                        OrganizationId = registration.OrganizationId,
                        Organization = registration.Organization,
                        TournamentId = registration.TournamentId,
                        Tournament = registration.Tournament,
                        AutoSuffix = tournamentRegistrationsManager.GenerateAutosuffix(currentOrganizationId, tournamentId, teams),
                        Name = tournamentRegistrationsManager.GenerateTeamName(currentOrganizationId, tournamentId, teams)
                    };

                    tournamentRegistrationsManager.SetTeam(team, user);
                    viewModel.Teams.Add(new APIModels.Team(team));

                    teams = tournamentRegistrationsManager
                        .GetTeams(registration.TournamentId, registration.OrganizationId)
                        .OrderBy(t => t.Created)
                        .ToList(); ;
                }



                // add empty speakers to view model, if necessary

                foreach (var team in viewModel.Teams)
                {
                    var missingSpeakers = registration.Tournament.TeamSize - team.speakers.Count;
                    for (int i = 0; i < missingSpeakers; i++)
                    {
                        var speaker = new APIModels.User
                        {
                            firstname = Resources.TournamentRegistration.Display.Strings.DefaultFirstName,
                            lastname = Resources.TournamentRegistration.Display.Strings.DefaultLastName
                        };
                        team.speakers.Add(speaker);
                    }

                }
                #endregion



                #region Adjudicators

                // Adjudicators

                var adjudicators = tournamentRegistrationsManager
                    .GetAdjudicators(registration.TournamentId, registration.OrganizationId)
                    .OrderBy(t => t.Created)
                    .ToList();

                viewModel.AdjudicatorsCompleted = adjudicators.Count();

                // if we do not get as many adjudicators as confirmed, add empty adjudicators to view model


                // Add teams to view model

                foreach (var adjudicator in adjudicators)
                {
                    viewModel.Adjudicators.Add(new APIModels.Adjudicator(adjudicator));
                }

                var missingAdjudicators = registration.AdjudicatorsPaid - viewModel.Adjudicators.Count;

                for (int i = 0; i < missingAdjudicators; i++)
                {
                    viewModel.Adjudicators.Add(new APIModels.Adjudicator
                    {
                        organizationId = organizationId,
                        tournamentId = tournamentId,
                        user = new APIModels.User
                        {
                            firstname = Resources.TournamentRegistration.Display.Strings.DefaultFirstName,
                            lastname = Resources.TournamentRegistration.Display.Strings.DefaultLastName
                        }
                    });
                }



                #endregion
                ViewBag.Tab = tab;
                return View(viewModel);
            }

            // if we did not find the registration, display the organization instead

            return RedirectToAction("Display", "Organization");
        }
        public async Task<ActionResult> PrintAccountStatement(Guid tournamentId, Guid? organizationId)
        {
            var ident = HttpContext.User.Identity as ClaimsIdentity;
            var currentOrganizationIdNullable = (await userManager.FindByIdAsync(ident.GetUserId())).CurrentOrganizationId;
            var currentOrganizationId = (Guid)(currentOrganizationIdNullable == null ? Guid.Empty : currentOrganizationIdNullable);

            if (currentOrganizationId == Guid.Empty)
            {
                return RedirectToAction("Select", "Organization", new { returnUrl = HttpContext.Request.RawUrl });
            }

            var user = userManager.FindByName(ident.Name);

            TournamentUserRole tournamentRole = null;
            if (organizationId != null && user != null)
            {
                tournamentRole = unitOfWork.GetRepository<TournamentUserRole>().Get(
                                          r => r.TournamentId == tournamentId
                                              && r.UserId == user.Id
                                              && r.Role == TournamentRole.SlotManager)
                                              .FirstOrDefault();
                if (tournamentRole != null)
                {
                    currentOrganizationId = (Guid)organizationId;
                }
            }


            if (!userManager.HasOrganizationRole(user.Id, currentOrganizationId, OrganizationRole.Delegate)
                && tournamentRole == null)
            {
                return RedirectToAction("Index", "Home");
            }

            var registration = unitOfWork.GetRepository<TournamentOrganizationRegistration>().GetById(tournamentId, currentOrganizationId);

            if (registration != null)
            {
                TournamentOrganizationRegistrationViewModel viewModel = new TournamentOrganizationRegistrationViewModel
                {
                    Registration = registration,
                    Bookings = bookingManager.GetBookings(registration.OrganizationId, registration.TournamentId)
                };
                return View(viewModel);
            }

            return RedirectToAction("Display", "Organization");
        }
Beispiel #3
0
        public async Task<ActionResult> OrganizationDetails(Guid id)
        {

            var ident = HttpContext.User.Identity as ClaimsIdentity;
            var tournamentId = (await (userManager.FindByIdAsync(ident.GetUserId()))).CurrentTournamentId;
            var currentTournamentId = (Guid)(tournamentId == null ? Guid.Empty : tournamentId);

            var registration = registrationManager.GetRegistration(currentTournamentId, id);

            TournamentOrganizationRegistrationViewModel registrationViewModel = null;
            if (registration != null)
            {
                registrationViewModel = new TournamentOrganizationRegistrationViewModel
                {
                    Registration = registration,
                    Bookings = bookingManager.GetBookings(id, currentTournamentId)
                };
            }



            return View(registrationViewModel);
        }