Beispiel #1
0
        public async Task <BaseResponseDto <PostDto> > Handle(CreatePostRequest request, CancellationToken cancellationToken)
        {
            BaseResponseDto <PostDto> response = new BaseResponseDto <PostDto>();

            try
            {
                var post = new Post
                {
                    Body       = request.Body,
                    Classid    = request.Classid,
                    CreatedAt  = DateTime.Now,
                    ModifiedAt = DateTime.Now,
                    Title      = request.Title,
                    Userid     = request.Userid
                };
                await _repositoryWrapper.Post.Create(post);

                if (await _repositoryWrapper.SaveChangesAsync())
                {
                    response.Data = post.Adapt <PostDto>();
                }
                else
                {
                    response.Errors.Add("Veri tabanı kayıt esnasında bir sorun oluştu.");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.InnerException.Message);
                response.Errors.Add(ex.InnerException.Message);
                response.Errors.Add("Post oluşturulurken bir hata oluştu.");
            }
            return(response);
        }
Beispiel #2
0
        public async Task <PlayerPostDTO> GetPostDTOAsync(Guid id)
        {
            Post          post    = GetPost(id);
            PlayerPostDTO postDTO = post?.Adapt <PlayerPostDTO>();

            return(post?.ReplayId is null
                                ? postDTO
                                : postDTO with
            {
                Replay = await _replayService.GetReplayDTOAsync(post.ReplayId.Value)
            });
Beispiel #3
0
        public void TestMappingFromDictionary()
        {
            var config = new TypeAdapterConfig();

            config.NewConfig <Post, Post>()
            .Map(nameof(Post.Dic) + ".Name", nameof(Post.Dic) + ".Name");

            var p1 = new Post {
                Dic = new Dictionary <string, string> {
                    { "Name", "test" }, { "Secret", "password" }
                }
            };
            var p2 = new Post();

            p1.Adapt(p2, config);

            p2.Dic["Name"].ShouldBe("test");
        }
Beispiel #4
0
        public void TestMappingToSelf()
        {
            var config = new TypeAdapterConfig();

            config.NewConfig <Post, Post>()
            .Map(nameof(Post.Secret), x => default(string))
            .Map(nameof(Post.Dic) + ".Secret", x => default(string));

            var p1 = new Post
            {
                Secret = "Test",
                Dic    = new Dictionary <string, string>
                {
                    { "Secret", "test" },
                    { "B", "test2" }
                }
            };

            p1.Adapt(p1, config);
            p1.Dic["Secret"].ShouldBeNull();
            p1.Secret.ShouldBeNull();
        }
Beispiel #5
0
        private async Task <PageDetailDto> getPageDetailAsync(Post post)
        {
            if (post == null)
            {
                return(null);
            }

            string postTypeSlug = post.PostType.Slug;
            string lang         = post.Language.LangKey;

            var result = post.Adapt <PageDetailDto>();

            //result.PostTypeSlug = PostType.PAGE;
            result.PostTypeTitle = post.PostType.Title;
            result.LangKey       = post.Language.LangKey;

            if (post.ParentId.HasValue)
            {
                var parentPage = await _repository.FindAsync(post.ParentId.Value);

                result.ParentTitle     = parentPage.Title;
                result.PagePathDisplay = $"{parentPage.Title}/{post.Title}";
                result.Parent          = new ParentPageDto {
                    Slug  = parentPage.Slug,
                    Title = parentPage.Title,
                    Id    = parentPage.Id
                };
                result.RelatedPages = await _repository
                                      .Query()
                                      .Where(_ => _.ParentId == post.ParentId)
                                      .Where(_ => _.PostType.Slug == PostType.PAGE)
                                      .Where(_ => _.Language.LangKey == lang)
                                      .AddPublishedRules()
                                      .Select(p => new RelatedPageDto {
                    Title        = p.Title,
                    AltTitle     = p.AltTitle,
                    ParentId     = p.ParentId,
                    Id           = p.Id,
                    ParentTitle  = post.Title,
                    IconName     = p.IconName,
                    PostTypeSlug = postTypeSlug,
                    Slug         = post.Slug
                }).ToListAsync();
            }
            else
            {
                var hasSubPages = await _repository
                                  .Query()
                                  .AnyAsync(_ => _.ParentId == post.Id);

                if (hasSubPages)
                {
                    result.RelatedPages = await _repository
                                          .Query()
                                          .Where(_ => _.ParentId == post.Id)
                                          .Where(_ => _.PostType.Slug == PostType.PAGE)
                                          .Where(_ => _.Language.LangKey == lang)
                                          .AddPublishedRules()
                                          .Select(p => new RelatedPageDto {
                        Title        = p.Title,
                        AltTitle     = p.AltTitle,
                        ParentId     = p.ParentId,
                        Id           = p.Id,
                        ParentTitle  = post.Title,
                        IconName     = p.IconName,
                        PostTypeSlug = postTypeSlug,
                        Slug         = post.Slug
                    }).ToListAsync();
                }
            }

            var headerImageMeta = await _metaRepository
                                  .GetPostMetaAsync(
                post.Id,
                "headerImage"
                );

            if (headerImageMeta != null)
            {
                result.HeaderImage = headerImageMeta.MetaValue;
            }

            return(await Task.FromResult(result));
        }
        async public Task <BlogPostDto> AddBlogPostAsync(BlogPostDto post)
        {
            if (post == null)
            {
                throw new ArgumentNullException("blogPost");
            }

            //Post newPost = post.Adapt<Post>();
            //newPost.CreatedAt = DateTime.UtcNow;
            //newPost.UpdatedAt = DateTime.UtcNow;
            //newPost.PostStatusId = (int)post.PostStatus;
            Post newPost = post.Adapt <Post>();

            newPost.CreatedAt  = DateTime.UtcNow;
            newPost.UpdatedAt  = DateTime.UtcNow;
            newPost.PostStatus = null;
            //Post znewPost = new Post()
            //{
            //    Title = post.Title,
            //    PostContent = post.PostContent,
            //    Excerpt = post.Excerpt,
            //    PostStatusId = (int)post.PostStatusId,
            //    CommentStatusId = (int)post.CommentStatusId,
            //    CommentCount = 0,
            //    CreatedAt = DateTime.UtcNow,
            //    UpdatedAt = DateTime.UtcNow,
            //};
            Context.Post.Add(newPost);

            BlogPost newBlogPost = new BlogPost()
            {
                BlogId = post.BlogId,
                Post   = newPost
            };

            Context.BlogPost.Add(newBlogPost);

            Dictionary <string, Tag> existingTags = Context.Tag.Where(i =>
                                                                      post.Tags.Contains(i.Name)).ToDictionary(i => i.Name.ToLower());

            foreach (string tag in post.Tags)
            {
                Tag t = existingTags.ContainsKey(tag.ToLower()) ? existingTags[tag.ToLower()] : null;
                if (t == null)
                {
                    t = new Tag()
                    {
                        Name = tag, Active = true, CreatedAt = DateTime.UtcNow
                    };
                }
                Context.PostTag.Add(new PostTag()
                {
                    Post = newPost, Tag = t, CreatedAt = DateTime.UtcNow
                });
            }

            PostAuthor primaryPostAuthor = new PostAuthor()
            {
                AuthorId  = post.PrimaryAuthorId,
                Post      = newPost,
                IsPrimary = true,
                ListOrder = 1,
            };

            Context.PostAuthor.Add(primaryPostAuthor);

            await Context.SaveChangesAsync();

            post        = newPost.Adapt <BlogPostDto>();
            post.BlogId = newBlogPost.BlogId;
            return(post);
        }