コード例 #1
0
        protected override async Task Handle(AddCommentRequest request, CancellationToken cancellationToken)
        {
            if (!(await store.Load <RoomService, RoomServiceId>(RoomServiceId.CreateFor(request.RoomServiceId)) is RoomService roomService))
            {
                throw new RoomServiceNotFoundException(request.RoomServiceId.ToString());
            }

            roomService.AddComment(request.Text, EmployeeId.CreateFor(request.EmployeeId));

            await store.Save <RoomService, RoomServiceId>(roomService);
        }
コード例 #2
0
ファイル: Comment.cs プロジェクト: jorgeolive/DDD-UOCHotels
        protected override void When(object @event)
        {
            switch (@event)
            {
            case CommentSubmitted e:

                this.CommentBy = EmployeeId.CreateFor(e.SubmmitedBy);
                Text           = e.Text;
                CreatedOn      = DateTime.UtcNow;
                this.Id        = new CommentId(Guid.NewGuid());

                break;
            }
            ;
        }
コード例 #3
0
        protected override async Task Handle(AddRoomIncidentRequest request, CancellationToken cancellationToken)
        {
            if ((await _roomRepository.GetById(request.RoomId)) != null &&
                (await _employeeRepository.GetById(request.EmployeeId)) != null)
            {
                var roomIncident = RoomIncident.CreateFor(
                    EmployeeId.CreateFor(request.EmployeeId),
                    RoomId.CreateFor(request.RoomId),
                    request.Severity,
                    request.Comment,
                    request.CreatedOn);

                await _store.Save <RoomIncident, RoomIncidentId>(roomIncident);
            }
            else
            {
                throw new InvalidOperationException("Room or employee doesnt exist");
            }
        }
コード例 #4
0
        protected override void When(object @event)
        {
            switch (@event)
            {
            case PictureAdded e:

                this.Pictures.Add(new Uri(e.Uri));
                break;

            case RoomIncidentCreated e:
            {
                this.Id                  = RoomIncidentId.CreateFor(e.RoomIncidentId);
                this.Comment             = e.Comment;
                this.AssociatedRoomId    = RoomId.CreateFor(e.RoomId);
                this.CreatedOn           = e.CreatedOn;
                this.Severity            = e.Severity;
                this.AssociatedEmployeId = EmployeeId.CreateFor(e.EmployeeId);
            }
            break;
            }
        }
コード例 #5
0
        protected override void When(object @event)
        {
            switch (@event)
            {
            case ServiceCreated e:

                Id = new RoomServiceId(e.ServiceId);
                AssociatedRoomId = new RoomId(e.RoomId);
                ServicedById     = EmployeeId.CreateFor(e.EmployeeId);
                break;

            case ServicePlanned e:

                PlannedOn = e.PlannedOn;
                Status    = RoomServiceStatus.Planned;
                break;

            case ServiceFinished e:

                EndTimeStamp = e.Timestamp;
                Status       = RoomServiceStatus.Completed;
                break;

            case ServiceStarted e:

                StartTimeStamp = e.StartTimestamp;
                Status         = RoomServiceStatus.Started;
                break;

            case CommentSubmitted e:

                var comment = new Comment(Apply);
                ApplyToEntity(comment, e);     //
                this.Comments.Add(comment);
                break;
            }
        }
コード例 #6
0
        protected override async Task Handle(CreateRoomServiceRequest request, CancellationToken cancellationToken)
        {
            var room = await _roomRepository.GetById(request.RoomId);

            if (room == null)
            {
                throw new RoomNotFoundException($"RoomId {request.RoomId.ToString()} does not exist.");
            }

            var employee = await _employeeRepository.GetById(request.EmployeeId);

            if (employee == null)
            {
                throw new EmployeeNotFoundException($"Employee {request.EmployeeId.ToString()} does not exist.");
            }

            var roomService = RoomService.CreateFor(RoomId.CreateFor(request.RoomId), EmployeeId.CreateFor(request.EmployeeId));

            await eventStore.Save <RoomService, RoomServiceId>(roomService);

            //We send the integration events after transaction is ok.
            foreach (var @event in roomService.GetChanges())
            {
                await _mediator.Publish(@event);
            }
        }