public async Task <Result> Update(UpdateBlogCategoryDto updateBlogCategoryDto) { var blogCategory = await FirstOrDefaultAsync(c => c.Id == updateBlogCategoryDto.Id); if (blogCategory == null) { return(Result.Failed(new NotFoundObjectResult(new ApiMessage { Message = ResponseMessage.BlogCategoryNotFound }))); } if (blogCategory.ParentId != updateBlogCategoryDto.ParentId) { var parentBlog = await FirstOrDefaultAsync(u => u.Id == updateBlogCategoryDto.ParentId); if (parentBlog == null) { return(Result.Failed(new BadRequestObjectResult(new ApiMessage { Message = ResponseMessage.InvalidBlogCategoryId }))); } blogCategory.ParentCategory = parentBlog; } _mapper.Map(updateBlogCategoryDto, blogCategory); await Context.SaveChangesAsync(); return(Result.SuccessFull()); }
public async Task <IActionResult> Update(int id, [FromBody] UpdateBlogCategoryDto updateBlogCategoryDto) { updateBlogCategoryDto.Id = id; var result = await _unitOfWork.BlogCategoryService.Update(updateBlogCategoryDto); if (!result.Success) { return(result.ApiResult); } return(NoContent()); }