示例#1
0
        public async Task <bool> Handle(IssueChangeIsPrivateCommand message, CancellationToken ct)
        {
            if (await _issueRepository.GetAsync(message.Id) is not {
            } issueEntity)
            {
                _logger.LogError("Issue with Id {Id} was not found", message.Id);
                return(false);
            }

            if (issueEntity.IsPrivate != message.IsPrivate)
            {
                _logger.LogError("Issue with Id {Id} has already the correct IsPrivate value", message.Id);
                return(false);
            }

            var oldIsPrivate = issueEntity.IsPrivate;

            issueEntity.SetIsPrivate(message.IsPrivate);
            _issueRepository.Update(issueEntity);

            if (await _issueRepository.UnitOfWork.SaveEntitiesAsync(ct))
            {
                var issueDTO = Mapper.Map(issueEntity);
                await _eventPublisher.Publish(new IssueChangedIsPrivateIntegrationEvent(issueDTO, oldIsPrivate), ct);

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        public async Task <bool> Handle(IssueRemoveCommand message, CancellationToken ct)
        {
            if (await _issueRepository.GetAsync(message.Id) is not {
            } issueEntity)
            {
                _logger.LogError("Issue with Id {Id} was not found", message.Id);
                return(false);
            }

            if (await _nexusModsIssueQueries.ExistsAsync(issueEntity.NexusModsGameId, issueEntity.NexusModsModId, issueEntity.Id, ct))
            {
                _logger.LogError("Issue with Id {Id} still exists in NexusMods!", message.Id);
                return(false);
            }

            issueEntity.Remove();
            _issueRepository.Update(issueEntity);

            if (await _issueRepository.UnitOfWork.SaveEntitiesAsync(ct))
            {
                var issueDTO = Mapper.Map(issueEntity);
                await _eventPublisher.Publish(new IssueRemovedIntegrationEvent(issueDTO), ct);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <bool> Handle(IssueAddNewReplyCommand message, CancellationToken ct)
        {
            if (await _issueRepository.GetAsync(message.Id) is not {
            } issueEntity)
            {
                _logger.LogError("Issue with Id {Id} was not found! IssueReply Id {ReplyId}", message.Id, message.ReplyId);
                return(false);
            }

            if (issueEntity.Replies.FirstOrDefault(r => r.Id == message.ReplyId) is { } existingReplyEntity)
            {
                _logger.LogError("Issue with Id {Id} has already the reply! Existing: {@ExistingIssueReply}, new: {@Message}", message.Id, existingReplyEntity, message);
                return(false);
            }

            var issueReplyEntity = issueEntity.AddReplyEntity(message.ReplyId, message.Author, message.AuthorUrl, message.AvatarUrl, message.Content, false, message.TimeOfPost);

            _issueRepository.Update(issueEntity);

            if (await _issueRepository.UnitOfWork.SaveEntitiesAsync(ct))
            {
                var issueDTO      = Mapper.Map(issueEntity);
                var issueReplyDTO = Mapper.Map(issueReplyEntity);
                await _eventPublisher.Publish(new IssueAddedReplyIntegrationEvent(issueDTO, issueReplyDTO), ct);

                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <bool> Handle(IssueAddNewCommand message, CancellationToken ct)
        {
            if (await _issueRepository.GetAsync(message.Id) is { } existingIssueEntity)
            {
                if (existingIssueEntity.IsDeleted)
                {
                    existingIssueEntity.Return();
                    return(await _issueRepository.UnitOfWork.SaveEntitiesAsync(ct));
                }

                _logger.LogError("Issue with Id {Id} already exist, is not deleted. Existing: {@ExistingIssue}, new: {Message}", message.Id, existingIssueEntity, message);
                return(false);
            }

            var issueEntity = Mapper.Map(message, await _issueRepository.GetStatusAsync(message.StatusId), await _issueRepository.GetPriorityAsync(message.PriorityId));

            _issueRepository.Add(issueEntity);

            if (await _issueRepository.UnitOfWork.SaveEntitiesAsync(ct))
            {
                var issueDTO = Mapper.Map(issueEntity);
                await _eventPublisher.Publish(new IssueAddedIntegrationEvent(issueDTO), ct);

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        public async Task <bool> Handle(IssueRemoveReplyCommand message, CancellationToken ct)
        {
            if (await _issueRepository.GetAsync(message.Id) is not {
            } issueEntity)
            {
                _logger.LogError("Issue with Id {Id} was not found", message.Id);
                return(false);
            }

            if (issueEntity.Replies.FirstOrDefault(r => r.Id == message.ReplyId) is not {
            } existingReplyEntity)
            {
                _logger.LogError("Issue with Id {Id} doesn't have the reply! IssueReply Id {ReplyId}", message.Id, message.ReplyId);
                return(false);
            }

            if (await _nexusModsIssueQueries.ExistsReplyAsync(issueEntity.NexusModsGameId, issueEntity.NexusModsModId, existingReplyEntity.OwnerId, existingReplyEntity.Id, ct))
            {
                _logger.LogError("Issue Reply with Id {ReplyId} still exists in NexusMods!", message.ReplyId);
                return(false);
            }

            var issueReply = issueEntity.RemoveReplyEntity(message.ReplyId) !;

            _issueRepository.Update(issueEntity);

            if (await _issueRepository.UnitOfWork.SaveEntitiesAsync(ct))
            {
                var issueDTO      = Mapper.Map(issueEntity);
                var issueReplyDTO = Mapper.Map(issueReply);
                await _eventPublisher.Publish(new IssueRemovedReplyIntegrationEvent(issueDTO, issueReplyDTO), ct);

                return(true);
            }
            else
            {
                return(false);
            }
        }