public IActionResult SaveEntity(BlogCategoryViewModel blogCategoryVm) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { blogCategoryVm.SeoAlias = TextHelper.ToUnsignString(blogCategoryVm.Name); if (blogCategoryVm.Id == 0) { _blogCategoryService.Add(blogCategoryVm); } else { _blogCategoryService.Update(blogCategoryVm); } _blogCategoryService.Save(); return(new OkObjectResult(blogCategoryVm)); } }
public ActionResult SaveCategory(BlogCategory category) { var c = new BlogCategory(); if (category != null) { if (category.ID > 0) { c = (BlogCategory)_categoryService.GetByID(category.ID); } c.Name = category.Name; _categoryService.Save(c); } return(Json(new { Message = "Category saved!", Status = "success", ReturnUrl = "/Blog" })); }