public async Task <BlogResponse> CreatePostAsync(CreatePostInput input) { var response = new BlogResponse(); var tags = await _tags.GetListAsync(); var newTags = input.Tags.Where(item => !tags.Any(x => x.Name == item)).Select(x => new Tag { Name = x, Alias = x.ToLower() }); if (newTags.Any()) { await _tags.InsertManyAsync(newTags); } var post = new Post { Title = input.Title, Author = input.Author, Url = input.Url.GeneratePostUrl(input.CreatedAt.ToDateTime()), Markdown = input.Markdown, Category = await _categories.GetAsync(input.CategoryId.ToObjectId()), Tags = await _tags.GetListAsync(input.Tags), CreatedAt = input.CreatedAt.ToDateTime() }; await _posts.InsertAsync(post); return(response); }
public async Task <IActionResult> Create(CreatePostInput model) { if (ModelState.IsValid) { // createdById alanini doldur model.CreatedById = User.FindFirst(ClaimTypes.NameIdentifier).Value; model.CreatedBy = User.FindFirst(ClaimTypes.Name).Value; // createService e gonder var createService = await _postService.Create(model); // hata yoksa Index e redirect et if (createService.Succeeded) { return(RedirectToAction("Index")); } // hata varsa hatayi ModelState e ekle ModelState.AddModelError(string.Empty, createService.ErrorMessage); } var categoryList = await _categoryService.GetAll(); ViewBag.CategoryDDL = categoryList.Result.Select(x => new SelectListItem { Selected = false, Text = x.Name, Value = x.Id.ToString() }).ToList(); return(View(model)); }
public async Task <ApplicationResult <PostDto> > Create(CreatePostInput input) { try { // useri al var user = await _userManager.FindByIdAsync(input.CreatedById); // maple Post newPost = _mapper.Map <Post>(input); newPost.CreatedBy = user.UserName; // context e ekle await _context.Posts.AddAsync(newPost); // kaydet await _context.SaveChangesAsync(); // ve dto'yu maple ve return et return(await Get(newPost.Id)); } catch (Exception ex) { return(new ApplicationResult <PostDto> { Result = new PostDto(), Succeeded = false, ErrorMessage = ex.Message }); } }
public async Task <PostListDto> Create(CreatePostInput input) { var post = ObjectMapper.Map <Post>(input); var result = await _postRepository.InsertAsync(post); return(ObjectMapper.Map <PostListDto>(result)); }
public async Task <ActionResult <ApplicationResult <PostDto> > > Post([FromBody] CreatePostInput input) { var result = await _postService.Create(input); if (result.Succeeded) { return(result); } return(NotFound(result)); }
public async Task Create(CreatePostInput input) { var entity = new Post(input.Name, input.Content, input.BlogId, AbpSession.UserId.Value); foreach (var inputTag in input.Tags) { entity.AssignTag(new Tag(inputTag.Name)); } await _manager.Create(entity); }
public async Task CreatePost() { var options = new DbContextOptionsBuilder <ApplicationUserDbContext>().UseInMemoryDatabase(databaseName: "Test_PostCreate").Options; MapperConfiguration mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new AutoMapperProfile()); }); IMapper mapper = mappingConfig.CreateMapper(); ApplicationResult <CategoryDto> resultCreateCategory = new ApplicationResult <CategoryDto>(); // create category using (var inMemoryContext = new ApplicationUserDbContext(options)) { CategoryServiceShould categoryShould = new CategoryServiceShould(); resultCreateCategory = await categoryShould.CreateCategory(inMemoryContext, mapper); } // check create category ApplicationResult <PostDto> resultPost = new ApplicationResult <PostDto>(); using (var inMemoryContext = new ApplicationUserDbContext(options)) { CategoryServiceShould categoryShould = new CategoryServiceShould(); await categoryShould.AssertCreatedCategory(inMemoryContext, resultCreateCategory); // create post var service = new PostService(inMemoryContext, mapper); CreatePostInput fakePost = new CreatePostInput { CategoryId = resultCreateCategory.Result.Id, Content = "Lorem Ipsum Dolor Sit Amet", Title = "Lorem Ipsum Dolor", UrlName = "lorem-ipsum-dolor", CreatedBy = "Tester1", CreatedById = Guid.NewGuid().ToString() }; resultPost = await service.Create(fakePost); } // check post create service using (var inMemoryContext = new ApplicationUserDbContext(options)) { Assert.True(resultPost.Succeeded); Assert.NotNull(resultPost.Result); Assert.Equal(1, await inMemoryContext.Posts.CountAsync()); var item = await inMemoryContext.Posts.FirstAsync(); Assert.Equal("Tester1", item.CreatedBy); Assert.Equal("Lorem Ipsum Dolor", item.Title); Assert.Equal("lorem-ipsum-dolor", item.UrlName); Assert.Equal("Lorem Ipsum Dolor Sit Amet", item.Content); Assert.Equal(resultCreateCategory.Result.Id, item.CategoryId); } }
public async Task Create(CreatePostInput input) { // Is the user the author of the blog? var blog = await _blogManager.FindByIdAsync(input.BlogId); if (blog?.AuthorId != AbpSession.UserId && AbpSession.UserId != input.AuthorId) { return; } var post = ObjectMapper.Map <Post>(input); await _postManager.CreateAsync(post); }
public async Task CreatePost(CreatePostInput input) { await _postRepository.InsertAsync(input.MapTo <Post>()); }
public async Task CreatePostAsync(CreatePostInput input) { var @post = Post.Create(AbpSession.GetTenantId(), input.Title, AbpSession.GetUserId(), input.Summary, input.Tags, input.Content, input.CatagoryId); await _postManager.CreatePostAsync(@post); }