async Task <ResponseDto <string> > IRequestHandler <CreateArticleCommand, ResponseDto <string> > .Handle(CreateArticleCommand command, CancellationToken cancellationToken)
        {
            var result = Validate <string, CreateArticleCommandValidator, CreateArticleCommand>(command);

            if (result.ErrorOccurred)
            {
                return(result);
            }

            var article = new ArticleTableEntity
            {
                PartitionKey = command.PartitionKey,
                RowKey       = Guid.NewGuid().ToString(),
                Content      = command.Content,
                Title        = command.Title
            };

            result.Object = await _articleTableStorageRepository.Create(article);

            return(result);
        }
Example #2
0
        async Task <ResponseDto <int> > IRequestHandler <CreateArticleCommand, ResponseDto <int> > .Handle(CreateArticleCommand command, CancellationToken cancellationToken)
        {
            var result = Validate <int, CreateArticleCommandValidator, CreateArticleCommand>(command);

            if (result.ErrorOccurred)
            {
                return(result);
            }

            var category = await _articleCategoryRepository.Get(command.CategoryId);

            if (category == null)
            {
                result.Errors.Add("Category not found.");
                return(result);
            }

            var article = new Article
            {
                Id       = command.Id,
                Content  = command.Content,
                Title    = command.Title,
                Category = category
            };

            result.Object = await _articleRepository.CreateAsync(article);

            return(result);
        }