public static SlugReadModel ToReadModel(this PostSlugEntity slugEntity) => new SlugReadModel { Path = slugEntity.Path, IsDefault = slugEntity.IsDefault, CreatedOn = slugEntity.CreatedOnUtc };
public async Task CreatePost(CreatePostCommand createPostCommand) { var authorId = createPostCommand.CreatedBy.Id; var createdBy = await _blogDbContext.Users.SingleOrDefaultAsync(x => x.Id == authorId); var claims = await GetCreatorClaims(authorId); var slug = new PostSlugEntity { Path = createPostCommand.Slug, IsDefault = true, CreatedBy = createdBy, CreatedOnUtc = DateTime.UtcNow }; var postEntity = new PostEntity { Title = createPostCommand.Title, Abstract = createPostCommand.Abstract, Content = createPostCommand.Content, Language = "en-US", Format = PostFormatEntity.Html, CreatedBy = createdBy, CreatedOnUtc = DateTime.UtcNow, CreationIpAddress = createPostCommand.IPAddress, Slugs = new List <PostSlugEntity> { slug }, Tags = new Collection <PostTagEntity>(createPostCommand.Tags.Select(t => new PostTagEntity { Tag = new TagEntity { Name = t } }).ToList()), ApprovalStatus = createPostCommand.Approved ? ApprovalStatusEntity.Approved : ApprovalStatusEntity.Disapproved }; await _blogDbContext.AddAsync(postEntity); await _blogDbContext.SaveChangesAsync(); }