コード例 #1
0
ファイル: Post.cs プロジェクト: jesubu/BlogCodeReview
        public static Result <Post> Create(PostEditorDto editor)
        {
            Result result = Validate(editor);

            if (result.IsFailure)
            {
                return(Result.Fail <Post>(result.Error));
            }

            return(Result.Ok(new Post(editor)));
        }
コード例 #2
0
ファイル: Post.cs プロジェクト: jesubu/BlogCodeReview
        public static Result Validate(PostEditorDto editor)
        {
            var autorValidationResult = ValidateAutor(editor.Autor);

            var titelValidationResult = ValidateTitle(editor.Title);

            var slugValidationResult = ValidateSlug(editor.Slug);

            // More validations if needed
            // ...

            return(Result.Combine(autorValidationResult, titelValidationResult, slugValidationResult));
        }
コード例 #3
0
        public static PostEditorDto ToPostEditorDto(this PostEditorViewModel postEditorViewModel)
        {
            var postEditorDto = new PostEditorDto();

            postEditorDto.InjectFrom(postEditorViewModel);
            postEditorDto.HtmlContent = postEditorViewModel.ContentHtml;

            foreach (var tagName in postEditorViewModel.Tags.Split(PostEditorViewModel.TagSeparator).ToList())
            {
                postEditorDto.Tags.Add(tagName);
            }

            return(postEditorDto);
        }
コード例 #4
0
ファイル: Post.cs プロジェクト: jesubu/BlogCodeReview
        public void MapEditorValues(PostEditorDto postEditor)
        {
            var validationResult = Validate(postEditor);

            if (validationResult.IsFailure)
            {
                throw new Exception(validationResult.Error);
            }

            Title       = postEditor.Title;
            Subtitle    = postEditor.Subtitle;
            Slug        = postEditor.Slug.Replace(" ", "-"); // Todo: Move to set propery? It would be compatible with EF?
            DatePost    = postEditor.DatePost;
            HtmlContent = postEditor.HtmlContent;
            Autor       = postEditor.Autor;
        }
コード例 #5
0
        public async Task <Result> UpdatePost(PostEditorDto editorPost)
        {
            var validationPostResult = Post.Validate(editorPost);

            if (validationPostResult.IsFailure)
            {
                return(validationPostResult);
            }

            Post post = await GetPostById(editorPost.Id);

            post.MapEditorValues(editorPost);

            _tagMapper.MapTagsToEntity(post, editorPost.Tags);

            await _db.SaveChangesAsync();

            return(Result.Ok());
        }
コード例 #6
0
        public async Task <Result> CreatePost(PostEditorDto editorPost)
        {
            var createPostResult = Post.Create(editorPost);

            if (createPostResult.IsFailure)
            {
                return(createPostResult);
            }

            Post post = createPostResult.Value;

            _tagMapper.MapTagsToEntity(post, editorPost.Tags);

            _db.Posts.Add(post);
            await _db.SaveChangesAsync();

            editorPost.Id = post.Id;

            return(Result.Ok());
        }
コード例 #7
0
ファイル: Post.cs プロジェクト: jesubu/BlogCodeReview
 private Post(PostEditorDto postEditor) : this()
 {
     MapEditorValues(postEditor);
 }