Example #1
0
 public void UserRegisteredForTournament(User user, TournamentOrganizationRegistration registration, Boolean adjudicator, string personalDataLink)
 {
     var role = adjudicator ? Resources.Strings.Adjudicator : Resources.Strings.Speaker;
     var message = CreateEMailMessage(new List<String> { user.NewEMail });
     message.Subject = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentSubject,
         role
     );
     message.Body = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentBody,
         user.FirstName,
         registration.Organization.Name,
         role,
         registration.Tournament.Name,
         personalDataLink
     );
     message.HTMLBody = String.Format
     (
         Resources.DebRegCommunication.SendMail.Strings.UserRegisteredForTournamentBodyHTML,
         user.FirstName,
         registration.Organization.Name,
         role,
         registration.Tournament.Name,
         personalDataLink
     );
     mailService.SendCompleted += mailService_SendCompleted;
     mailService.Send(message);
 }
        public TournamentOrganizationRegistration AddRegistration(Guid tournamentId, Guid organizationId, Guid billedOrganizationId, int teamsWanted, int adjudicatorsWanted, String notes, User user)
        {
            if (tournamentId != Guid.Empty
                && organizationId != Guid.Empty
                && billedOrganizationId != Guid.Empty
                && (teamsWanted > 0 || adjudicatorsWanted > 0))
            {

                TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    OrganizationId = organizationId,
                    BilledOrganizationId = billedOrganizationId,
                    TeamsWanted = teamsWanted,
                    AdjudicatorsWanted = adjudicatorsWanted,
                    TeamsGranted = 0,
                    TeamsPaid = 0,
                    AdjudicatorsGranted = 0,
                    AdjudicatorsPaid = 0,
                    LockAutoAssign = false,
                    OrganizationStatusDraft = true,
                    Notes = notes
                };
                registration.UpdateTrackingData(user);
                SetBookingCode(registration);
                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();
                return registration;
            }
            return null;
        }
        public void SetTeam_WithExistingTeam_ShouldUpdateTeam()
        {
            #region Arrange
            // Arrange

            Guid tournamentId;
            Tournament tournament;

            {
                #region Create tournament

                // Create tournament
                tournamentId = Guid.NewGuid();
                tournament = new Tournament
                {
                    Id = tournamentId,
                    TeamSize = 2
                };

                #endregion
            }

            Guid organizationId = Guid.NewGuid();
            TournamentOrganizationRegistration registration;
            {
                #region Create registration

                // Create registration

                registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                    TeamsWanted = 2,
                    TeamsGranted = 2,
                    TeamsPaid = 2,
                };

                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();

                #endregion

            }

            Team team;
            {
                #region Create original team

                // Create original team

                team = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId
                };

                for (int i = 0; i < tournament.TeamSize; i++)
                {
                    var speaker = new User
                    {
                        Id = Guid.NewGuid().ToString()
                    };
                    var task = userManager.CreateAsync(speaker);
                    if (!task.IsCompleted) { task.Wait(); }
                    team.Speaker.Add(speaker);
                }

                unitOfWork.GetRepository<Team>().Insert(team);
                unitOfWork.Save();

                #endregion
            }

            Team updatedTeam;
            {
                #region Create updated team

                // Create updated Team

                updatedTeam = new Team
                {
                    Id = team.Id,
                    TournamentId = team.TournamentId,
                    Tournament = tournament,
                    OrganizationId = team.OrganizationId,
                };

                foreach (var speaker in team.Speaker)
                {
                    updatedTeam.Speaker.Add(speaker);
                }

                {
                    #region Replace first speaker

                    // Replace first speaker

                    User newSpeaker = new User
                    {
                        Id = Guid.NewGuid().ToString()
                    };
                    var task = userManager.CreateAsync(newSpeaker);
                    if (!task.IsCompleted) { task.Wait(); }

                    updatedTeam.Speaker[0] = newSpeaker;

                    #endregion
                }

                #endregion
            }
            User user = new User();

            #endregion

            // Act

            var result = tournamentRegistrationsManager.SetTeam(updatedTeam, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TeamUpdated, result);
            var teamId = team.Id;
            team = null;
            team = tournamentRegistrationsManager.GetTeam(teamId);
            Assert.AreEqual(updatedTeam.Speaker[0].Id, team.Speaker[0].Id);


        }
        public void SetTeam_WithNewTeam_ShouldCreateNewTeam()
        {
            #region Arrange
            // Arrange

            Guid tournamentId = Guid.NewGuid();
            Tournament tournament = new Tournament
            {
                Id = tournamentId,
                TeamSize = 2
            };

            Guid organizationId = Guid.NewGuid();

            TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
            {
                TournamentId = tournamentId,
                Tournament = tournament,
                OrganizationId = organizationId,
                TeamsWanted = 2,
                TeamsGranted = 2,
                TeamsPaid = 2,
            };

            unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
            unitOfWork.Save();

            Team team = new Team
            {
                Id = Guid.NewGuid(),
                TournamentId = tournamentId,
                Tournament = tournament,
                OrganizationId = organizationId
            };

            for (int i = 0; i < tournament.TeamSize; i++)
            {
                var speaker = new User
                {
                    Id = Guid.NewGuid().ToString()
                };
                var task = userManager.CreateAsync(speaker);
                if (!task.IsCompleted) { task.Wait(); }
                team.Speaker.Add(speaker);
            }

            User user = new User();

            #endregion
            // Act

            var result = tournamentRegistrationsManager.SetTeam(team, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TeamAdded, result);
            var teamId = team.Id;
            team = null;
            team = tournamentRegistrationsManager.GetTeam(teamId);
            Assert.AreEqual(teamId, team.Id);

        }
        private TournamentOrganizationRegistration CreateTournamentOrganizationRegistration()
        {
            Organization organization = new Organization
            {
                Id = Guid.NewGuid(),
            };
            Organization linkedOrganization = new Organization
            {
                Id = Guid.NewGuid(),
                LinkedOrganization = organization,
                LinkedOrganizationId = organization.Id
            };
            organization.LinkedOrganizations.Add(linkedOrganization);

            TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
            {
                OrganizationId = organization.Id,
                Organization = organization,
                TournamentId = Guid.NewGuid(),
            };
            tournamentRegistrationsManager.SetBookingCode(registration);
            return registration;
        }
        private void AddRegistrationWithOrganizationToRepository(Guid organizationId, Guid tournamentId, String abbreviation)
        {
            Organization organization = new Organization
            {
                Id = organizationId,
                Abbreviation = abbreviation
            };

            TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
            {
                TournamentId = tournamentId,
                OrganizationId = organizationId,
                Organization = organization
            };

            unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
            unitOfWork.Save();
        }
        public void SetTeam_WithMaximumTeamsExceeded_ShouldReturnTooManyTeams()
        {
            #region Arrange
            // Arrange

            Guid tournamentId;
            Tournament tournament;

            {
                #region Create tournament

                // Create tournament
                tournamentId = Guid.NewGuid();
                tournament = new Tournament
                {
                    Id = tournamentId,
                    TeamSize = 2
                };

                #endregion
            }

            Guid organizationId = Guid.NewGuid();
            TournamentOrganizationRegistration registration;
            {
                #region Create registration

                // Create registration

                registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                    TeamsWanted = 2,
                    TeamsGranted = 2,
                    TeamsPaid = 2,
                };

                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();

                #endregion

            }

            Team team;

            {
                #region Create maximum number of teams

                // Create maximum number of teams

                for (int i = 0; i < registration.TeamsPaid; i++)
                {
                    team = new Team
                    {
                        Id = Guid.NewGuid(),
                        TournamentId = tournamentId,
                        Tournament = tournament,
                        OrganizationId = organizationId
                    };

                    for (int s = 0; s < tournament.TeamSize; s++)
                    {
                        var speaker = new User
                        {
                            Id = Guid.NewGuid().ToString()
                        };
                        var task = userManager.CreateAsync(speaker);
                        if (!task.IsCompleted) { task.Wait(); }
                        team.Speaker.Add(speaker);
                    }

                    unitOfWork.GetRepository<Team>().Insert(team);
                    unitOfWork.Save();
                }

                #endregion
            }

            {
                #region Create new team

                // Create new Team

                team = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                };

                #endregion
            }
            User user = new User();

            #endregion

            // Act

            var result = tournamentRegistrationsManager.SetTeam(team, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.TooManyTeams, result);

        }
        public void SetTeam_WithSpeakerInOutherTeam_ShouldReturnSpeakerAlreadyInOtherTeam()
        {
            #region Arrange
            // Arrange

            Guid tournamentId;
            Tournament tournament;

            {
                #region Create tournament

                // Create tournament
                tournamentId = Guid.NewGuid();
                tournament = new Tournament
                {
                    Id = tournamentId,
                    TeamSize = 2
                };

                #endregion
            }

            Guid organizationId = Guid.NewGuid();
            TournamentOrganizationRegistration registration;
            {
                #region Create registration

                // Create registration

                registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId,
                    TeamsWanted = 2,
                    TeamsGranted = 2,
                    TeamsPaid = 2,
                };

                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();

                #endregion

            }

            Team team;
            {
                #region Create original team

                // Create original team

                team = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = tournamentId,
                    Tournament = tournament,
                    OrganizationId = organizationId
                };

                for (int i = 0; i < tournament.TeamSize; i++)
                {
                    var speaker = new User
                    {
                        Id = Guid.NewGuid().ToString()
                    };
                    var task = userManager.CreateAsync(speaker);
                    if (!task.IsCompleted) { task.Wait(); }
                    team.Speaker.Add(speaker);
                }

                unitOfWork.GetRepository<Team>().Insert(team);
                unitOfWork.Save();

                #endregion
            }

            Team newTeam;
            {
                #region Create new team

                // Create new Team

                newTeam = new Team
                {
                    Id = Guid.NewGuid(),
                    TournamentId = team.TournamentId,
                    Tournament = tournament,
                    OrganizationId = team.OrganizationId,
                };

                // Add new speaker as first speaker

                User newSpeaker = new User { Id = Guid.NewGuid().ToString() };
                var task = userManager.CreateAsync(newSpeaker);
                if (!task.IsCompleted) { task.Wait(); }
                newTeam.Speaker.Add(newSpeaker);

                // Add speaker of another team as second speaker

                newTeam.Speaker.Add(team.Speaker.First());

                #endregion
            }
            User user = new User();

            #endregion

            // Act

            var result = tournamentRegistrationsManager.SetTeam(newTeam, user);

            // Assert

            Assert.AreEqual(SetTeamOrAdjudicatorResult.SpeakerAlreadyInOtherTeam, result);

        }
Example #9
0
        public void DeleteTournament_WithValidUser_ShouldDeleteTournamentAndRegistrations()
        {
            // Arrange
            #region ARRANGE

            #region CREATE ORIGINAL TOURNAMENT

            var tournament = CreateTournament();

            unitOfWork.GetRepository<Tournament>().Insert(tournament);
            unitOfWork.Save();
            #endregion

            #region CREATE REGISTRATIONS
            for (int i = 0; i < 10; i++)
            {
                TournamentOrganizationRegistration registration = new TournamentOrganizationRegistration
                {
                    TournamentId = tournament.Id,
                    OrganizationId = Guid.NewGuid()
                };
                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                unitOfWork.Save();
                tournament.Registrations.Add(registration);
            }
            #endregion


            var user = CreateUserWithOrganizationRole(organization, OrganizationRole.OrganizationTournamentManager);

            #endregion

            // Act

            tournamentManager.DeleteTournament(tournament.Id, user);

            // Assert

            #region ASSERT

            var savedTournament = unitOfWork.GetRepository<Tournament>().GetById(tournament.Id);
            Assert.IsTrue(savedTournament.Deleted);
            Assert.AreEqual(user.Id, savedTournament.ModifiedBy.Id);
            Assert.IsNotNull(savedTournament.Modified);
            foreach (var registration in savedTournament.Registrations)
            {
                Assert.IsTrue(registration.Deleted);
                Assert.AreEqual(user.Id, registration.ModifiedBy.Id);
                Assert.IsNotNull(registration.Modified);
            }

            #endregion
        }
        public ActionResult Delete(TournamentOrganizationRegistration registration)
        {
            var ident = HttpContext.User.Identity as ClaimsIdentity;
            var organizationId = userManager.FindById(ident.GetUserId()).CurrentOrganizationId;
            var currentOrganizationId = (Guid)(organizationId == null ? Guid.Empty : organizationId);

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

            //var user = unitOfWork.GetRepository<User>().GetById(ident.GetUserId());
            if (!userManager.HasOrganizationRole(ident.GetUserId(), currentOrganizationId, OrganizationRole.Delegate))
            {
                return RedirectToAction("Index", "Home");
            }

            var tournament = unitOfWork.GetRepository<Tournament>().GetById(registration.TournamentId);
            if (IsOpenForRegistration(tournament))
            {
                if (registration != null)
                {
                    unitOfWork.GetRepository<TournamentOrganizationRegistration>().Delete(registration.TournamentId, registration.OrganizationId);
                    try
                    {
                        unitOfWork.Save();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return RedirectToAction("Index");
        }
        public ActionResult Register(TournamentOrganizationRegistration registration)
        {
            var ident = HttpContext.User.Identity as ClaimsIdentity;
            var organizationId = userManager.FindById(ident.GetUserId()).CurrentOrganizationId;
            var currentOrganizationId = (Guid)(organizationId == null ? Guid.Empty : organizationId);
            if (currentOrganizationId == Guid.Empty)
            {
                return RedirectToAction("Select", "Organization", new { returnUrl = HttpContext.Request.RawUrl });
            }

            var organization = unitOfWork.GetRepository<Organization>().GetById(registration.OrganizationId);

            var user = unitOfWork.GetRepository<User>().GetById(ident.GetUserId());
            //if (user == null) {
            //    return RedirectToAction("Login", "User");
            //}


            if (userManager.HasOrganizationRole(user.Id, currentOrganizationId, OrganizationRole.Delegate))
            {
                var tournament = unitOfWork.GetRepository<Tournament>().GetById(registration.TournamentId);

                if (tournament != null
                    && IsOpenForRegistration(tournament))
                {


                    // check if university is required

                    if (tournament.UniversityRequired
                        && !IsUniversity(organization))
                    {
                        return View("UniversityRequired");
                    }

                    // check number of teams and adjudicators
                    if (registration.TeamsWanted > tournament.TeamCap)
                    {
                        ModelState.AddModelError("", Resources.TournamentRegistration.Strings.ErrorTeamsWantedExceedTeamCap);
                    }

                    if (registration.AdjudicatorsWanted > tournament.AdjudicatorCap)
                    {
                        ModelState.AddModelError("", Resources.TournamentRegistration.Strings.ErrorAdjWantedExceedAdjCap);
                    }

                    if (tournament.AdjucatorSubtract != null
                        && registration.AdjudicatorsWanted < registration.TeamsWanted - (int)tournament.AdjucatorSubtract)
                    {

                        ModelState.AddModelError("", Resources.TournamentRegistration.Strings.ErrorAdjWantedBelowPolicy);
                    }

                    // check if organization can be billed
                    if (organization.Id != registration.BilledOrganizationId
                        && organization.LinkedOrganizations.FirstOrDefault(
                            o => o.Id == registration.BilledOrganizationId) == null)
                    {

                        ModelState.AddModelError("BilledOrganizationId", Resources.TournamentRegistration.Strings.ErrorOrganizationCannotBeBilled);
                    }


                    // Everything okay, so register
                    if (ModelState.IsValid)
                    {

                        try
                        {
                            var registrationSaved = unitOfWork.GetRepository<TournamentOrganizationRegistration>().GetById(registration.TournamentId, registration.OrganizationId);

                            // if old registration found, update it
                            if (registrationSaved != null)
                            {
                                registrationSaved.BilledOrganizationId = registration.BilledOrganizationId;
                                registrationSaved.TeamsWanted = registration.TeamsWanted;
                                registrationSaved.AdjudicatorsWanted = registration.AdjudicatorsWanted;
                                registrationSaved.Notes = registration.Notes;
                                registrationSaved.UpdateTrackingData(user);
                            }

                            // otherwise create a new one
                            else
                            {
                                registration.TeamsGranted = 0;
                                registration.TeamsPaid = 0;
                                registration.AdjudicatorsGranted = 0;
                                registration.AdjudicatorsPaid = 0;
                                registration.UpdateTrackingData(user);
                                unitOfWork.GetRepository<TournamentOrganizationRegistration>().Insert(registration);
                            }
                            unitOfWork.Save();
                            return RedirectToAction("Display", new { organizationId = registration.OrganizationId, tournamentId = registration.TournamentId });
                        }
                        catch (DataException)
                        {
                            ModelState.AddModelError("", Resources.Strings.ErrorSaveChanges);
                        }
                    }
                    else
                    {
                        registration.OrganizationId = currentOrganizationId;
                        registration.Organization = unitOfWork.GetRepository<Organization>().GetById(currentOrganizationId);
                        // On errors, display registration form again
                        return View(registration);
                    }


                }
                else
                {
                    // tournament not found or not open for registration
                    return RedirectToAction("Index");
                }
            }

            // if user is not authorized, redirect to home
            return RedirectToAction("Home", "Index");
        }
        // GET: TournamentRegistration/Register
        /// <summary>
        /// Displays a view for the organization to register for a tournament.
        /// </summary>
        /// <param name="tournamentId">The id of the tournament, the organization should register for.</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.
        /// Tournament registration view.</returns>
        public ActionResult Register(Guid tournamentId)
        {
            var ident = HttpContext.User.Identity as ClaimsIdentity;
            var organizationId = userManager.FindById(ident.GetUserId()).CurrentOrganizationId;
            var currentOrganizationId = (Guid)(organizationId == null ? Guid.Empty : organizationId);
            //var currentOrganizationId = claimsManager.GetCurrentOrganizationId(ident);

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

            // var user = userManager.FindByName(ident.Name);
            if (!userManager.HasOrganizationRole(ident.GetUserId(), currentOrganizationId, OrganizationRole.Delegate))
            {
                return RedirectToAction("Index", "Home");
            }

            var tournament = unitOfWork.GetRepository<Tournament>().GetById(tournamentId);

            if (tournament != null
                && IsOpenForRegistration(tournament))
            {
                TournamentOrganizationRegistration registration = unitOfWork.GetRepository<TournamentOrganizationRegistration>().GetById(tournamentId, currentOrganizationId);

                if (registration == null)
                {

                    // check if university is required
                    var organization = unitOfWork.GetRepository<Organization>().GetById(currentOrganizationId);

                    if (tournament.UniversityRequired)
                    {
                        if (organization == null || !organization.Universitary)
                        {
                            ViewBag.returnUrl = HttpContext.Request.Url;
                            return View("UniversityRequired", new TournamentOrganizationRegistration
                            {
                                OrganizationId = currentOrganizationId,
                                TournamentId = tournament.Id
                            });
                        }
                    }


                    registration = new TournamentOrganizationRegistration
                    {
                        OrganizationId = currentOrganizationId,
                        Organization = organization,
                        TournamentId = tournamentId,
                        TeamsWanted = 1
                    };
                    if (tournament.AdjucatorSubtract != null)
                    {
                        registration.AdjudicatorsWanted = registration.TeamsWanted - (int)tournament.AdjucatorSubtract;
                    }
                }
                return View(registration);
            }

            return RedirectToAction("Index");
        }
Example #13
0
        private void SendAssignmentNotification(TournamentOrganizationRegistration registration, String paymentPageUrl, User user) {

            if (registration != null
                && registration.Tournament != null) {

                var balance = String.Format("{0} {1}",
                    registration.Tournament.Currency.Symbol,
                    bookingManager.GetBalance(registration.OrganizationId, registration.TournamentId));



                // Create message

                EMailMessage message = new EMailMessage();
                message.To = new List<string>();
                var delegates = from ua in registration.Organization.UserAssociations
                                where ua.Role == OrganizationRole.Delegate
                                select ua.User;
#if DEBUG
                message.To.Add(mailService.FromAddress);

#else
                foreach (var deleg in delegates) {
                    message.To.Add(deleg.Email);
                }
#endif
                message.Bcc = new List<string>();
                message.Bcc.Add(mailService.FromAddress);
                message.Subject = String.Format(
                    Resources.Facade.PaymentManager.Strings.ConfirmationNotificationSubject,
                    registration.Tournament.Name);

                Object[] messageVariables = new Object[] {
                    registration.Tournament.Name,               // {0}
                    registration.Organization.Name,             // {1}
                    registration.TeamsPaid,                  // {2}
                    registration.AdjudicatorsPaid,           // {3}
                    balance,                                    // {4}
                    String.Format(paymentPageUrl,               // {5}
                        registration.TournamentId,
                        registration.OrganizationId)            
                };
                message.Body = String.Format(
                    Resources.Facade.PaymentManager.Strings.ConfirmationNotificationBody,
                    messageVariables);



#if DEBUG
                mailService.Send(message);
#endif
                message.HTMLBody = String.Format(
                    Resources.Facade.PaymentManager.Strings.ConfirmationNotificationHTMLBody,
                    messageVariables);

                Guid messageId = Guid.NewGuid();
                sentMessages.Add(messageId, new SlotAssignmentStatusMessage {
                    Registration = registration,
                    MailMessage = message,
                    User = user
                });

                mailService.Send(message, messageId);
            }

        }
        public void SetBookingCode(TournamentOrganizationRegistration registration)
        {

            // if registration does not have a booking code, create one

            if (String.IsNullOrEmpty(registration.BookingCode))
            {
                // Generate tournament unique booking code
                String bookingCode;
                do
                {
                    bookingCode = BookingCodeHelper.GuidToBookingCode(Guid.NewGuid(), 6);
                } while (GetRegistration(bookingCode, registration.TournamentId) != null);
                registration.BookingCode = bookingCode;
            }
        }