public async Task Handle(RemoveClientServiceCommand message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var record = await _repository.Get(message.AnnouncementId);

            if (record == null || (record.Subject != message.Subject))
            {
                return;
            }

            if (!await _repository.Delete(record.Id))
            {
                return;
            }

            _eventPublisher.Publish(new ClientServiceRemovedEvent
            {
                AnnouncementId = message.AnnouncementId,
                Subject        = message.Subject,
                CommonId       = message.CommonId
            });
        }
        public async Task <IActionResult> Execute(RemoveClientServiceCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }


            var validationResult = await _validator.Validate(command);

            if (!validationResult.IsValid)
            {
                var error = _responseBuilder.GetError(ErrorCodes.Server, validationResult.Message);
                return(_controllerHelper.BuildResponse(System.Net.HttpStatusCode.BadRequest, error));
            }

            _commandSender.Send(command);
            return(new OkResult());
        }
Ejemplo n.º 3
0
        public async Task <RemoveClientServiceValidationResult> Validate(RemoveClientServiceCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var announcement = await _repository.Get(command.AnnouncementId);

            if (announcement == null)
            {
                return(new RemoveClientServiceValidationResult(ErrorDescriptions.TheAnnouncementDoesntExist));
            }

            if (announcement.Subject != command.Subject)
            {
                return(new RemoveClientServiceValidationResult(ErrorDescriptions.TheAnnouncementCannotBeRemovedByYou));
            }

            return(new RemoveClientServiceValidationResult());
        }