コード例 #1
0
        public async Task <IActionResult> LeaveCommentAsync([FromBody] CommentDetailsViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status422UnprocessableEntity));
                }

                var endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleWriteServiceQueue);

                await endPoint.Send <IInsertCommentCommand>(new
                {
                    model.AddedBy,
                    model.AddedByEmail,
                    model.ArticleId,
                    model.CategoryId,
                    model.Body
                });

                return(Accepted());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #2
0
        public async Task <IActionResult> InsertCategoryAsync(AddCategoryViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status422UnprocessableEntity));
                }

                var endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleWriteServiceQueue);

                await endPoint.Send <IInsertCategoryCommand>(new
                {
                    model.Description,
                    model.ImageUrl,
                    model.Importance,
                    model.Title
                });

                return(Accepted());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #3
0
        public async Task <IActionResult> UpdateArticleAsync(Guid articleId, [FromBody] EditArticleViewModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest());
                }

                if (!ModelState.IsValid)
                {
                    return(StatusCode(StatusCodes.Status422UnprocessableEntity));
                }

                var endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleWriteServiceQueue);

                await endPoint.Send <IUpdateArticleCommand>(new
                {
                    model.Id,
                    model.Body
                });

                return(Accepted());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #4
0
        private async Task SendEventAsync(Article article)
        {
            ISendEndpoint endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleSagaQueue);

            foreach (IEvent @event in article.GetUncommittedEvents())
            {
                var obj = (ISagaArticleUpdatedEvent)@event;
                await endPoint.Send <ISagaArticleUpdatedEvent>(new
                {
                    obj.AggregateId,
                    obj.Abstract,
                    obj.Approved,
                    obj.Body,
                    obj.CategoryId,
                    obj.City,
                    obj.CommentsEnabled,
                    obj.Country,
                    obj.ExpireDate,
                    obj.Listed,
                    obj.OnlyForMembers,
                    obj.ReleaseDate,
                    obj.State,
                    obj.Title
                });
            }
        }
コード例 #5
0
        public async Task SendEvent(IEvent @event)
        {
            ISendEndpoint endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleSagaQueue);

            var obj = (ISagaCategoryInsertedEvent)@event;
            await endPoint.Send <ISagaCategoryInsertedEvent>(new
            {
                obj.AggregateId,
                obj.AddedBy,
                obj.AddedDate,
            });
        }
        private async Task SendEventAsync(Article article)
        {
            ISendEndpoint endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleSagaQueue);

            foreach (IEvent @event in article.GetUncommittedEvents())
            {
                var obj = (ISagaArticleViewCountIncrementedEvent)@event;
                await endPoint.Send <ISagaArticleViewCountIncrementedEvent>(new
                {
                    obj.AggregateId
                });
            }
        }
コード例 #7
0
        private async Task SendEventAsync(Category category)
        {
            ISendEndpoint endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleSagaQueue);

            foreach (IEvent @event in category.GetUncommittedEvents())
            {
                var obj = (ISagaCategoryDeletedEvent)@event;
                await endPoint.Send <ISagaCategoryDeletedEvent>(new
                {
                    obj.AggregateId
                });
            }
        }
コード例 #8
0
        private async Task SendEventAsync(Category category)
        {
            ISendEndpoint endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleSagaQueue);

            foreach (IEvent @event in category.GetUncommittedEvents())
            {
                var obj = (ISagaCategoryUpdatedEvent)@event;
                await endPoint.Send <ISagaCategoryUpdatedEvent>(new
                {
                    obj.AggregateId,
                    obj.Description,
                    obj.ImageUrl,
                    obj.Importance,
                    obj.Title
                });
            }
        }
コード例 #9
0
        public async Task <IActionResult> DeleteArticleAsync(Guid articleId)
        {
            try
            {
                var endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleWriteServiceQueue);

                await endPoint.Send <IDeleteArticleCommand>(new
                {
                    Id = articleId
                });

                return(Accepted());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #10
0
        private async Task SendEventAsync(Article article)
        {
            ISendEndpoint endPoint = await BusConfigurator.GetEndPointAsync(RabbitMqConstants.ArticleSagaQueue);

            foreach (IEvent @event in article.GetUncommittedEvents())
            {
                var obj = (ISagaCommentInsertedEvent)@event;
                await endPoint.Send <ISagaCommentInsertedEvent>(new
                {
                    obj.AggregateId,
                    obj.AddedBy,
                    obj.AddedByEmail,
                    obj.AddedByIp,
                    obj.AddedDate,
                    obj.ArticleId,
                    obj.Body
                });
            }
        }