public async Task <Result <BlogCategoryDto> > Create(CreateBlogCategoryDto createBlogCategoryDto) { BlogCategory parentBlog = null; if (createBlogCategoryDto.ParentId != null) { parentBlog = await FirstOrDefaultAsync(u => u.Id == createBlogCategoryDto.ParentId); if (parentBlog == null) { return(Result <BlogCategoryDto> .Failed(new BadRequestObjectResult(new ApiMessage { Message = ResponseMessage.InvalidBlogCategoryId }))); } } var blogCategory = _mapper.Map(createBlogCategoryDto, new BlogCategory()); blogCategory.ParentCategory = parentBlog; await AddAsync(blogCategory); await Context.SaveChangesAsync(); return(Result <BlogCategoryDto> .SuccessFull(_mapper.Map <BlogCategoryDto>(blogCategory))); }
public async Task <IActionResult> Create([FromBody] CreateBlogCategoryDto createBlogCategoryDto) { var result = await _unitOfWork.BlogCategoryService.Create(createBlogCategoryDto); if (!result.Success) { return(result.ApiResult); } return(Created(Url.Link("GetCounty", new { result.Data.Id }), _mapper.Map <BlogCategoryDto>(result.Data))); }