public async Task <IActionResult> Execute(RemoveShopCommand removeShopCommand)
        {
            if (removeShopCommand == null)
            {
                throw new ArgumentNullException(nameof(removeShopCommand));
            }

            var validationResult = await _validator.Validate(removeShopCommand);

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

            _commandSender.Send(removeShopCommand);
            return(new OkResult());
        }
Exemple #2
0
        public async Task <RemoveShopValidationResult> Validate(RemoveShopCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var shop = await _shopRepository.Get(command.ShopId);

            if (shop == null)
            {
                return(new RemoveShopValidationResult(ErrorDescriptions.TheShopDoesntExist));
            }

            if (shop.Subject != command.Subject)
            {
                return(new RemoveShopValidationResult(ErrorDescriptions.TheShopCannotBeRemovedByYou));
            }

            return(new RemoveShopValidationResult());
        }
Exemple #3
0
        public async Task Handle(RemoveShopCommand message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var record = await _shopRepository.Get(message.ShopId);

            if (record == null)
            {
                return;
            }

            await _shopRepository.Remove(record);

            _eventPublisher.Publish(new ShopRemovedEvent
            {
                ShopId   = message.ShopId,
                Subject  = message.Subject,
                CommonId = message.CommonId
            });
        }