Ejemplo n.º 1
0
        private IEnumerable<SlotAssignmentViewModel> GetSlotAssignmentViewModels(Guid tournamentId, User user)
        {
            // Build wait list
            var waitList = tournamentRegistrationsManager.GetRegistrationsSortedByRank(tournamentId, user);

            // Get latest version
            var latestVersion = slotAssignmentManager.GetLatestVersion(tournamentId);
            if (latestVersion == null)
            {
                latestVersion = slotAssignmentManager.CreateVersion(tournamentId);
            }

            // Get assignments
            var assignments = slotManager.GetSlotAssignments(tournamentId, latestVersion, user);

            // Build view model
            List<SlotAssignmentViewModel> assignmentsViewModel = new List<SlotAssignmentViewModel>();
            foreach (var registration in waitList)
            {
                var assignment = assignments.FirstOrDefault(
                    a => a.OrganizationId == registration.OrganizationId);
                if (assignment == null)
                {
                    assignment = new SlotAssignment();
                }
                assignmentsViewModel.Add(new SlotAssignmentViewModel
                {
                    Assignment = assignment,
                    Registration = registration
                });
            }
            return assignmentsViewModel;
        }
Ejemplo n.º 2
0
 public void CopyTo(SlotAssignment target)
 {
     target.AdjucatorsGranted = this.AdjucatorsGranted;
     target.Created = this.Created;
     target.CreatedBy = this.CreatedBy;
     target.CreatedById = this.CreatedById;
     target.Modified = this.Modified;
     target.ModifiedBy = this.ModifiedBy;
     target.ModifiedById = this.ModifiedById;
     target.Organization = this.Organization;
     target.OrganizationId = this.OrganizationId;
     target.TeamsGranted = this.TeamsGranted;
     target.Tournament = this.Tournament;
     target.TournamentId = this.TournamentId;
     target.Version = this.Version;
     target.VersionId = this.VersionId;
 }
Ejemplo n.º 3
0
 public SlotAssignment Clone()
 {
     SlotAssignment result = new SlotAssignment();
     CopyTo(result);
     return result;
 }
Ejemplo n.º 4
0
        private SlotAssignment AssignAdjudicatorSlots(SlotAssignment assignment, int adjudicatorSlots, User user)
        {
            if (assignment.AdjucatorsGranted != adjudicatorSlots)
            {
                assignment.AdjucatorsGranted = adjudicatorSlots;
                assignment.UpdateTrackingData(user);

                unitOfWork.GetRepository<SlotAssignment>().Update(assignment);
                unitOfWork.Save();
            }

            return assignment;
        }
Ejemplo n.º 5
0
 private SlotAssignment CreateAssignment(Guid tournamentId, Guid organizationId, Guid versionId)
 {
     var savedAssignment = new SlotAssignment
     {
         TournamentId = tournamentId,
         OrganizationId = organizationId,
         VersionId = versionId,
         TeamsGranted = 0,
         AdjucatorsGranted = 0
     };
     unitOfWork.GetRepository<SlotAssignment>().Insert(savedAssignment);
     unitOfWork.Save();
     return savedAssignment;
 }
Ejemplo n.º 6
0
        private SlotAssignment AssignTeamSlots(SlotAssignment assignment, int teamSlots, User user)
        {
            if (assignment.TeamsGranted != teamSlots)
            {
                assignment.TeamsGranted = teamSlots;
                assignment.UpdateTrackingData(user);

                unitOfWork.GetRepository<SlotAssignment>().Update(assignment);
                unitOfWork.Save();
            }

            return assignment;
        }
Ejemplo n.º 7
0
        public IList<SlotAssignment> GetSlotAssignments(Guid tournamentId, DebReg.Models.Version version, User user)
        {
            var waitList = tournamentregistrationsManager.GetRegistrationsSortedByRank(tournamentId, user);
            // List<SlotAssignment> assignments = new List<SlotAssignment>();

            var assignments = slotAssignmentManager.GetSlotAssignments(tournamentId, version.Id).ToList();
            IList<SlotAssignment> result = new List<SlotAssignment>();

            // Create missing assignments

            foreach (var registration in waitList)
            {
                var currentAssignment = assignments.FirstOrDefault(a => a.OrganizationId == registration.OrganizationId);

                if (currentAssignment == null)
                {
                    currentAssignment = new SlotAssignment
                    {
                        Organization = registration.Organization,
                        OrganizationId = registration.OrganizationId,
                        TournamentId = registration.TournamentId,
                        TeamsGranted = 0,
                        AdjucatorsGranted = 0,
                        Version = version
                    };
                }
                result.Add(currentAssignment);
            }
            return assignments;
        }
Ejemplo n.º 8
0
        //private SlotAssignment CreateSlotAssignment(TournamentOrganizationRegistration registration, DebReg.Models.Version version) {
        //    return new SlotAssignment {
        //        AdjucatorsGranted = registration.AdjudicatorsGranted,
        //        OrganizationId = registration.OrganizationId,
        //        TeamsGranted = registration.TeamsGranted,
        //        TournamentId = registration.TournamentId,
        //        Version = version,
        //    };
        //}

        private void PublishAssignment(SlotAssignment assignment, DateTime paymentsDueDate, String paymentPageUrl, User user)
        {
            // Get Tournament and registration

            var tournament = tournamentManager.GetTournament(assignment.TournamentId);
            if (tournament == null) { return; }

            var registration = tournamentregistrationsManager.GetRegistration(assignment.TournamentId, assignment.OrganizationId);
            if (registration == null) { return; }

            // Compare assignments with previously published assignments

            var teamsDifference = assignment.TeamsGranted - registration.TeamsGranted;
            var adjudicatorsDifference = assignment.AdjucatorsGranted - registration.AdjudicatorsGranted;

            // Create bookings in balance

            if (tournament.TeamProduct != null && teamsDifference != 0)
            {
                bookingManager.AddBooking(
                    DateTime.UtcNow,
                    assignment.OrganizationId,
                    assignment.TournamentId,
                    tournament.TeamProduct,
                    teamsDifference,
                    false,                                     // Debit
                    teamsDifference > 0 ? (DateTime?)paymentsDueDate : null,    // PaymentsDueDate
                    user);
            }

            if (tournament.AdjudicatorProduct != null && adjudicatorsDifference != 0)
            {
                bookingManager.AddBooking(
                    DateTime.UtcNow,
                    assignment.OrganizationId,
                    assignment.TournamentId,
                    tournament.AdjudicatorProduct,
                    adjudicatorsDifference,
                    false,                                  // Debit
                    adjudicatorsDifference > 0 ? (DateTime?)paymentsDueDate : null, // PaymentsDueDate
                    user);
            }

            // If assigned slots are lower than confirmed, decrease confirmed slots

            var adjudicatorsPaid = registration.AdjudicatorsPaid;

            if (adjudicatorsPaid > assignment.AdjucatorsGranted)
            {
                adjudicatorsPaid = assignment.AdjucatorsGranted;
            }

            var teamsPaid = registration.TeamsPaid;
            if (teamsPaid > assignment.TeamsGranted)
            {
                teamsPaid = assignment.TeamsGranted;
            }

            if (teamsPaid != registration.TeamsPaid || adjudicatorsPaid != registration.AdjudicatorsPaid)
            {
                tournamentregistrationsManager.SetTeamsAndAdjudicatorsPaid(assignment.TournamentId, assignment.OrganizationId, teamsPaid, adjudicatorsPaid, user);
            }

            // Publish assignment in registration


            tournamentregistrationsManager.SetTeamsAndAdjudicatorsGranted(assignment.TournamentId, assignment.OrganizationId, assignment.TeamsGranted, assignment.AdjucatorsGranted, user);


            // Send mail to organization

            if (teamsDifference != 0 || adjudicatorsDifference != 0)
            {
                SendAssignmentNotification(registration, paymentsDueDate, paymentPageUrl, user);
            }
        }