Exemplo n.º 1
0
        private void ReplaceAuctionImage(UserReplaceAuctionImageCommand request, CancellationToken cancellationToken, CorrelationId correlationId)
        {
            var auction = _auctionRepository.FindAuction(request.AuctionId);

            if (auction == null)
            {
                throw new CommandException($"Cannot find auction {request.AuctionId}");
            }

            var file = File.ReadAllBytes(request.TempPath);

            File.Delete(request.TempPath);

            var img = new AuctionImageRepresentation(new AuctionImageMetadata(request.Extension), file);

            var newImg = _auctionImageService.AddAuctionImage(img);

            auction.ReplaceImage(newImg, request.ImgNum);

            _auctionRepository.UpdateAuction(auction);
            try
            {
                _eventBusService.Publish(auction.PendingEvents, correlationId, request);
            }
            catch (Exception)
            {
                _auctionImageService.RemoveAuctionImage(newImg);
                throw;
            }
        }
Exemplo n.º 2
0
        protected override Task <RequestStatus> HandleCommand(AddAuctionImageCommand request, CancellationToken cancellationToken)
        {
            var file = File.ReadAllBytes(request.TempPath);

            File.Delete(request.TempPath);

            var img = new AuctionImageRepresentation(new AuctionImageMetadata(request.Extension), file);

            var added = _auctionImageService.AddAuctionImage(img);

            request.AuctionCreateSession.AddOrReplaceImage(added, request.ImgNum);

            var response = RequestStatus.CreateFromCommandContext(request.CommandContext, Status.COMPLETED, new Dictionary <string, object>()
            {
                { "imgSz1", added.Size1Id },
                { "imgSz2", added.Size2Id },
                { "imgSz3", added.Size3Id }
            });

            _logger.LogDebug("Image added: {@img}", added);

            return(Task.FromResult(response));
        }
Exemplo n.º 3
0
        private void AddImage(UserAddAuctionImageCommand request, CancellationToken cancellationToken, CorrelationId correlationId)
        {
            var auction = _auctionRepository.FindAuction(request.AuctionId);

            if (auction == null)
            {
                throw new CommandException($"Cannot find auction {request.AuctionId}");
            }

            if (!auction.Owner.UserId.Equals(request.SignedInUser.UserId))
            {
                throw new CommandException(
                          $"User {request.SignedInUser.UserId} cannot modify auction ${auction.AggregateId}");
            }

            var file = File.ReadAllBytes(request.TempPath);

            File.Delete(request.TempPath);

            var img = new AuctionImageRepresentation(new AuctionImageMetadata(request.Extension), file);

            var newImg = _auctionImageService.AddAuctionImage(img);

            auction.AddImage(newImg);

            _auctionRepository.UpdateAuction(auction);
            try
            {
                _eventBusService.Publish(auction.PendingEvents, correlationId, request);
            }
            catch (Exception e)
            {
                _logger.LogWarning(e, "Error while trying to publish events");
                _auctionImageService.RemoveAuctionImage(newImg);
                throw;
            }
        }