public virtual async Task <BlogDto> CreateAsync(CreateBlogDto input) { return(await RequestAsync <BlogDto>(nameof(CreateAsync), new ClientProxyRequestTypeValue { { typeof(CreateBlogDto), input } })); }
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(); } } }
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); }
public void Post([FromBody] CreateBlogDto createBlogDto) { Blog blog = _mapper.Map <Blog>(createBlogDto); blog.CreateTime = DateTime.Now; _blogRepository.Insert(blog); }
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)); }
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))); }
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)); }
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 }; }
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); }
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); }
public static CreateBlogViewModel GetCreateBlogViewModel(CreateBlogDto createBlogDto) { return(new CreateBlogViewModel(createBlogDto.Title)); }
public Task <BlogDto> CreateAsync(CreateBlogDto input) { return(BlogAdminAppService.CreateAsync(input)); }
public async Task <BlogDto> CreateAsync(CreateBlogDto input) { return(await _blogManagementAppService.CreateAsync(input)); }
public async Task CreateBlogAsync([FromBody] CreateBlogDto createBlogDto) { await blogService.CreateBlogAsync(createBlogDto); }
public async Task <Blog> CreateBlogTransactionalTaskAsync([FromBody] CreateBlogDto createBlogDto) { return(await _blogService.CreateBlogTransactionalTaskAsync(createBlogDto)); }
public async Task CreateBlogTransactionalAsync([FromBody] CreateBlogDto createBlogDto) { await _blogService.CreateBlogTransactionalAsync(createBlogDto); }
public void CreateBlogTransactional([FromBody] CreateBlogDto createBlogDto, [FromServices] BlogService blogService2) { blogService2.CreateBlogTransactional(createBlogDto); }
public void CreateBlog([FromBody] CreateBlogDto createBlogDto) { _blogService.CreateBlog(createBlogDto); }
public async Task <BlogDto> Create(CreateBlogDto input) { return(await _blogAppService.Create(input)); }
public async Task <long> Create([FromBody] CreateBlogDto createDto, [FromServices] IGenericCreateHandler handler) => await ExecutionPlan.Execute( handler.ExecuteAsync <CreateBlogDto, Blog>, createDto);
public async Task CreateBlogUnitOfWorkAsync([FromBody] CreateBlogDto createBlogDto) { await _blogService.CreateBlogUnitOfWorkAsync(createBlogDto); }