예제 #1
0
 public virtual async Task <BlogDto> CreateAsync(CreateBlogDto input)
 {
     return(await RequestAsync <BlogDto>(nameof(CreateAsync), new ClientProxyRequestTypeValue
     {
         { typeof(CreateBlogDto), input }
     }));
 }
예제 #2
0
        public virtual async Task CreateBlogUnitOfWorkAsync(CreateBlogDto createBlogDto)
        {
            using (IUnitOfWork unitOfWork = _unitOfWorkManager.Begin())
            {
                try
                {
                    Blog blog = _mapper.Map <Blog>(createBlogDto);
                    blog.CreateTime = DateTime.Now;
                    await _blogRepository.InsertAsync(blog);

                    List <Tag> tags = new List <Tag>();
                    createBlogDto.Tags.ForEach(r =>
                    {
                        tags.Add(new Tag {
                            TagName = r
                        });
                    });
                    if (createBlogDto.Title == "abc")
                    {
                        throw new Exception("test exception CreateBlogTransactionalAsync");
                    }
                    await _tagRepository.InsertAsync(tags);

                    unitOfWork.Commit();
                }
                catch (Exception)
                {
                    unitOfWork.Rollback();
                }
            }
        }
예제 #3
0
        public async Task <IActionResult> CreateBlogAsync([FromBody] CreateBlogDto requestDto)
        {
            var entity = _mapper.Map <Blog>(requestDto);

            if (!Guid.TryParse(User.FindFirstValue("sub"), out Guid authorId))
            {
                throw new ArgumentException("Sub claim parsing failed");
            }
            entity.AuthourId = authorId;

            _logger.LogInformation($"User (ID #{authorId}) trying to create new blog");
            entity.Sanitize();
            if (!TryValidateModel(entity))
            {
                _logger.LogWarning($"User's DTO does not pass model validation after sanitizing. {requestDto}");
                return(BadRequest());
            }

            entity = await _blogs.CreateBlogAsync(entity);

            _logger.LogInformation($"User (ID #{authorId}) created new blog with identificator {entity.Id}");

            var result = _mapper.Map <BlogDto>(entity);

            return(Ok(result));
        }
        public void Post([FromBody] CreateBlogDto createBlogDto)
        {
            Blog blog = _mapper.Map <Blog>(createBlogDto);

            blog.CreateTime = DateTime.Now;
            _fsql.Insert <Blog>(blog).ExecuteAffrows();
        }
        public virtual async Task <Blog> CreateBlogTransactionalTaskAsync(CreateBlogDto createBlogDto)
        {
            Blog blog = _mapper.Map <Blog>(createBlogDto);

            blog.CreateTime = DateTime.Now;
            await _blogRepository.InsertAsync(blog);

            if (createBlogDto.Title == "abc")
            {
                throw new Exception("test exception CreateBlogTransactionalAsync");
            }
            //await _tagService.CreateTransactionalAsync(
            //    new Tag()
            //    {
            //        IsDeleted = false,
            //        TagName = "tagName",
            //        PostId = blog.Id
            //    });

            await _tagService.CreateAsync(
                new Tag()
            {
                IsDeleted = false,
                TagName   = "tagName",
                PostId    = blog.Id
            });

            return(blog);
        }
예제 #6
0
        public void Post([FromBody] CreateBlogDto createBlogDto)
        {
            Blog blog = _mapper.Map <Blog>(createBlogDto);

            blog.CreateTime = DateTime.Now;
            _blogRepository.Insert(blog);
        }
예제 #7
0
        public async Task <BlogDto> Create(CreateBlogDto input)
        {
            var newBlog = await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), input.Name, input.ShortName)
            {
                Description = input.Description
            });

            return(ObjectMapper.Map <Blog, BlogDto>(newBlog));
        }
예제 #8
0
        public async Task <IActionResult> Create([FromBody] CreateBlogDto createBlogDto)
        {
            var result = await _unitOfWork.BlogService.Create(createBlogDto, UserId);

            if (!result.Success)
            {
                return(result.ApiResult);
            }
            return(Created(Url.Link("GetCounty", new { result.Data.Id }), _mapper.Map <BlogDto>(result.Data)));
        }
예제 #9
0
    public virtual async Task <BlogDto> CreateAsync(CreateBlogDto input)
    {
        var blog = await BlogManager.CreateAsync(input.Name, input.Slug);

        await BlogRepository.InsertAsync(blog, autoSave : true);

        await BlogFeatureManager.SetDefaultsAsync(blog.Id);

        return(ObjectMapper.Map <Blog, BlogDto>(blog));
    }
예제 #10
0
        public async Task <IActionResult> Add(CreateBlogDto createBlogDto)
        {
            var createBlogViewModel = CustomMapper.GetCreateBlogViewModel(createBlogDto);

            var validationResult = await _blogService.Add(createBlogViewModel);

            if (validationResult.IsValid)
            {
                return(Ok());
            }

            return(BadRequest(validationResult.Errors));
        }
        private void Test()
        {
            CreateBlogDto createBlogDto = new CreateBlogDto()
            {
                Title   = "我是title",
                Content = "我是content"
            };

            Blog newBlog = new Blog()
            {
                Title   = createBlogDto.Title,
                Content = createBlogDto.Content
            };
        }
예제 #12
0
        public async Task<Result<BlogDto>> Create(CreateBlogDto createBlogDto, Guid userId)
        {
            var blogCategory =
                await Context.BlogCategories.FirstOrDefaultAsync(u => u.Id == createBlogDto.BlogCategoryId);
            if (blogCategory == null)
                return Result<BlogDto>.Failed(new BadRequestObjectResult(new ApiMessage
                    {Message = ResponseMessage.InvalidBlogCategoryId}));


            var blog = _mapper.Map(createBlogDto, new Blog());
            blog.BlogCategory = blogCategory;
            blog.UseId = userId;

            await AddAsync(blog);
            await Context.SaveChangesAsync();

            return Result<BlogDto>.SuccessFull(_mapper.Map<BlogDto>(blog));
        }
        public async Task CreateBlogAsync(CreateBlogDto createBlogDto)
        {
            Blog blog = _mapper.Map <Blog>(createBlogDto);

            blog.CreateTime = DateTime.Now;
            await _blogRepository.InsertAsync(blog);

            List <Tag> tags = new List <Tag>();

            createBlogDto.Tags.ForEach(r =>
            {
                tags.Add(new Tag {
                    TagName = r
                });
            });
            if (createBlogDto.Title == "abc")
            {
                throw new Exception("test exception");
            }
            await _tagRepository.InsertAsync(tags);
        }
        public virtual void CreateBlogTransactional(CreateBlogDto createBlogDto)
        {
            Blog blog = _mapper.Map <Blog>(createBlogDto);

            blog.CreateTime = DateTime.Now;
            _blogRepository.Insert(blog);

            List <Tag> tags = new List <Tag>();

            createBlogDto.Tags.ForEach(r =>
            {
                tags.Add(new Tag {
                    TagName = r
                });
            });
            if (createBlogDto.Title == "abc")
            {
                throw new Exception("test exception");
            }
            _tagRepository.Insert(tags);
        }
예제 #15
0
        public async Task <bool> CreateBlogAsync(CreateBlogDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Blog_Add);
            var blog = Mapper.Map <Blog>(input);

            input.SelectTags = input.SelectTags.Distinct().ToList();
            var tags = await _tagRepository.GetAllListAsync(p => input.SelectTags.Contains(p.Id));

            if (tags.Count > 0)
            {
                blog.BlogTags = new List <BlogTag>();
                var blogTags = tags.Select(p => new BlogTag()
                {
                    Tag = p
                });
                foreach (var iObj in blogTags)
                {
                    blog.BlogTags.Add(iObj);
                }
            }

            return(await _blogRepository.InsertAndGetIdAsync(blog) > 0);
        }
예제 #16
0
 public static CreateBlogViewModel GetCreateBlogViewModel(CreateBlogDto createBlogDto)
 {
     return(new CreateBlogViewModel(createBlogDto.Title));
 }
예제 #17
0
 public Task <BlogDto> CreateAsync(CreateBlogDto input)
 {
     return(BlogAdminAppService.CreateAsync(input));
 }
예제 #18
0
 public async Task <BlogDto> CreateAsync(CreateBlogDto input)
 {
     return(await _blogManagementAppService.CreateAsync(input));
 }
 public async Task CreateBlogAsync([FromBody] CreateBlogDto createBlogDto)
 {
     await blogService.CreateBlogAsync(createBlogDto);
 }
예제 #20
0
 public async Task <Blog> CreateBlogTransactionalTaskAsync([FromBody] CreateBlogDto createBlogDto)
 {
     return(await _blogService.CreateBlogTransactionalTaskAsync(createBlogDto));
 }
예제 #21
0
 public async Task CreateBlogTransactionalAsync([FromBody] CreateBlogDto createBlogDto)
 {
     await _blogService.CreateBlogTransactionalAsync(createBlogDto);
 }
예제 #22
0
 public void CreateBlogTransactional([FromBody] CreateBlogDto createBlogDto, [FromServices] BlogService blogService2)
 {
     blogService2.CreateBlogTransactional(createBlogDto);
 }
예제 #23
0
 public void CreateBlog([FromBody] CreateBlogDto createBlogDto)
 {
     _blogService.CreateBlog(createBlogDto);
 }
예제 #24
0
 public async Task <BlogDto> Create(CreateBlogDto input)
 {
     return(await _blogAppService.Create(input));
 }
예제 #25
0
 public async Task <long> Create([FromBody] CreateBlogDto createDto, [FromServices] IGenericCreateHandler handler)
 => await ExecutionPlan.Execute(
     handler.ExecuteAsync <CreateBlogDto, Blog>, createDto);
예제 #26
0
 public async Task CreateBlogUnitOfWorkAsync([FromBody] CreateBlogDto createBlogDto)
 {
     await _blogService.CreateBlogUnitOfWorkAsync(createBlogDto);
 }