예제 #1
0
        public void Execute(Guid seatId, string reason)
        {
            var seat = GetAggregate <Seat>(seatId);

            seat.Refuse(reason);

            var managerId = _notificationManagerQueries.GetNotificationManagerId(seat.SessionId);
            var manager   = GetAggregate <NotificationManager>(managerId);

            manager.SignalSeatRefused(seatId, seat.CompanyId);

            Agreement agreement = null;

            if (seat.AssociatedAgreementId.HasValue)
            {
                agreement = GetAggregate <Agreement>(seat.AssociatedAgreementId.Value);
                agreement.Revoke();
                manager.SignalAgreementRevoked(agreement.AggregateId);
            }

            var session = GetAggregate <Session>(seat.SessionId);

            if (seat.StudentId.HasValue)
            {
                session.ReleaseSeat(seat.StudentId.Value);
            }

            PublishUncommitedEvents(seat, agreement, session, manager);
        }
        public void Execute(Guid sessionId, Guid notificationId)
        {
            var managerId = _managerQueries.GetNotificationManagerId(sessionId);
            var manager   = GetAggregate <NotificationManager>(managerId);

            manager.Remove(notificationId);

            PublishUncommitedEvents(manager);
        }
예제 #3
0
        public Seat Execute(Guid sessionId, Guid?studentId, Guid companyId, bool sendNotification)
        {
            var session = GetAggregate <Session>(sessionId);
            var seat    = session.BookSeat(studentId, companyId);

            var managerId = _notificationManagerQueries.GetNotificationManagerId(sessionId);
            var manager   = GetAggregate <NotificationManager>(managerId);

            manager.SignalSeatCreated(seat.AggregateId, companyId, studentId, sendNotification);

            PublishUncommitedEvents(session, seat, manager);
            return(seat);
        }
        public void Execute(Guid seatId, Guid?newStudentId)
        {
            GuidAssert.AreNotEmpty(seatId);

            var seat = GetAggregate <Seat>(seatId, true);

            seat.UpdateStudent(newStudentId);

            var notificationManagerId = _notificationQueries.GetNotificationManagerId(seat.SessionId);
            var notificationManager   = GetAggregate <NotificationManager>(notificationManagerId, true);

            notificationManager.SignalSeatRedefined(seatId, seat.CompanyId, newStudentId);

            PublishUncommitedEvents(seat, notificationManager);
        }
예제 #5
0
        public void Execute(Guid seatId, bool sendNotification = true)
        {
            var seat = GetAggregate <Seat>(seatId);

            seat.Validate();

            var managerId = _notificationQueries.GetNotificationManagerId(seat.SessionId);
            var manager   = GetAggregate <NotificationManager>(managerId);

            if (sendNotification)
            {
                manager.SignalSeatValidated(seat.AggregateId, seat.CompanyId);
            }

            PublishUncommitedEvents(seat, manager);
        }
예제 #6
0
        public void Execute(Guid sessionId, Guid seatId, string reason)
        {
            var session = GetAggregate <Session>(sessionId);
            var seat    = GetAggregate <Seat>(seatId);

            if (seat.StudentId.HasValue)
            {
                session.ReleaseSeat(seat.StudentId.Value);
            }
            seat.Cancel(reason);

            var managerId = _notificationManagerQueries.GetNotificationManagerId(sessionId);
            var manager   = GetAggregate <NotificationManager>(managerId);

            manager.SignalSeatCanceled(seat.AggregateId, seat.CompanyId);

            PublishUncommitedEvents(session, seat);
        }
예제 #7
0
        public Agreement Execute(Guid contactId, IEnumerable <Guid> seatsIds, AgreementType agreementType)
        {
            CheckThereAreNoDuplicate(seatsIds);
            var  aggregatesToCommit = new List <AggregateRoot>();
            Guid?companyId          = null;

            var agreementNumber = _agreementQueries.GetNextAgreementNumber();

            if (agreementNumber <= 0)
            {
                throw new Exception("Impossible d'obtenir le numéro de convention.");
            }

            var agreement = Agreement.Create(contactId, agreementNumber, agreementType);

            aggregatesToCommit.Add(agreement);

            NotificationManager manager = null;

            foreach (var seatId in seatsIds)
            {
                var seat = GetAggregate <Seat>(seatId);
                if (manager == null)
                {
                    var managerId = _notificationQueries.GetNotificationManagerId(seat.SessionId);
                    manager = GetAggregate <NotificationManager>(managerId);
                    aggregatesToCommit.Add(manager);
                }

                if (companyId.HasValue && companyId.Value != seat.CompanyId)
                {
                    throw new AgreementCompanyException();
                }
                companyId = seat.CompanyId;

                seat.AssociateAgreement(agreement.AggregateId);
                manager.SignalAgreementAssociated(agreement.AggregateId, seat.AggregateId, seat.CompanyId);

                aggregatesToCommit.Add(seat);
            }

            PublishUncommitedEvents(aggregatesToCommit.ToArray());
            return(agreement);
        }