Exemple #1
0
        public async Task CreateWorks()
        {
            var model1 = new PostCreateServiceModel
            {
                Title      = this.testPost1.Title,
                Content    = this.testPost1.Content,
                AuthorId   = this.testUser1.Id,
                CategoryId = this.testCategory1.Id,
            };

            var model2 = new PostCreateServiceModel
            {
                Title      = this.testPost2.Title,
                Content    = this.testPost2.Content,
                AuthorId   = this.testUser2.Id,
                CategoryId = this.testCategory2.Id,
            };

            await this.postsService.CreatePostAsync(model1);

            await this.postsService.CreatePostAsync(model2);

            var isSuccessful = this.postsRepository.All().Count() == 2;

            Assert.True(isSuccessful);
        }
Exemple #2
0
        public async Task <IActionResult> AddPost(NewPostModel model)
        {
            model.AuthorId = this.userManager.GetUserId(this.User);
            var serviceModel = new PostCreateServiceModel
            {
                Content    = model.Content,
                Title      = model.Title,
                AuthorId   = model.AuthorId,
                CategoryId = model.CategoryId,
            };
            int postId = await this.postService.CreatePostAsync(serviceModel);

            return(this.RedirectToAction("Index", "Post", new { id = postId }));
        }
Exemple #3
0
        public async Task <int> CreatePostAsync(PostCreateServiceModel model)
        {
            var post = new Post
            {
                Title      = model.Title,
                Content    = new HtmlSanitizer().Sanitize(model.Content),
                AuthorId   = model.AuthorId,
                CategoryId = model.CategoryId,
            };

            await this.postsRepository.AddAsync(post);

            await this.postsRepository.SaveChangesAsync();

            return(post.Id);
        }