public IActionResult AddOrUpdateBlog(string dataJson) { var dataObj = JsonConvert.DeserializeObject <BlogModel>(dataJson); try { if (!string.IsNullOrWhiteSpace(dataObj.Id)) { var entity = _blogService.GetById(dataObj.Id); entity = dataObj.ToEntity(entity); _blogService.Update(entity); _blogService.UpdateToCategory(entity.Id, dataObj.CategoryId); } else { var entity = dataObj.ToEntity(); _blogService.Add(entity); _blogService.AddToCategory(new BlogCategory() { BlogId = entity.Id, CategoryId = dataObj.CategoryId }); } } catch (Exception ex) { return(Json(new { status = false, message = ex.Message })); } return(Json(new { status = true, message = "Lưu dữ liệu thành công" })); }