public ActionResult DeleteNewsCategory(int categoryId) { ArticleCategoryViewModel category = _categoryService.GetCategoryByID(categoryId); if (category == null) { TempData["SUCCESS"] = false; TempData["Message"] = "Không tìm thấy nội dung yêu cầu"; return(RedirectToAction("NewsCategory")); } //if (category.MainCategory.IsDefault) //{ // TempData["SUCCESS"] = false; // TempData["Message"] = string.Format(" {0} là danh mục mặc định, bạn không thể xóa mục này", category.MainCategory.CategoryName); // return RedirectToAction("NewsCategory"); //} try { _categoryService.Delete(category); TempData["SUCCESS"] = true; TempData["Message"] = string.Format(" {0} đã bị xóa khỏi hệ thống", category.ICArticleCategoryName); return(RedirectToAction("NewsCategory")); } catch (Exception ex) { //log.ErrorFormat("Error message: {0}. Access by {1}", ex.Message, User.FullName); TempData["SUCCESS"] = false; TempData["Message"] = string.Format(ex.Message, category.ICArticleCategoryName); return(RedirectToAction("NewsCategory")); } }
public async Task <ActionResult> Delete(ArticleCategoryViewModel model) { try { // TODO: Add delete logic here _articleCategoryService.Delete(model.Category); await _articleCategoryService.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { return(View()); } }
public ResponseInfoModel Delete([FromBody] DeleteArticleCategoryInput input) { ResponseInfoModel json = new ResponseInfoModel() { Success = 1, Result = new object() }; try { int[] idInts = ConvertStringToIntArr(input.ids); //if (_articleCategoryService.GetList(a=>idInts.Contains(a.ParentID)).Any()) //{ // throw new UserFriendlyException("栏目下有文章不可删除"); //} if (_articleArticleCategoryService.GetNoTrackingList(a => idInts.Contains(a.ArticleCategorysID)).Any()) { throw new UserFriendlyException("栏目下有文章不可删除"); } if (!_articleCategoryService.Delete(a => idInts.Contains(a.ID))) { json.Success = 0; json.Result = LocalizationConst.DeleteFail; } else { foreach (var id in idInts) { _logService.Insert(new Log() { ActionContent = LocalizationConst.Delete, SourceType = _moduleName, SourceID = id, LogUserID = input.userID, LogTime = DateTime.Now, LogIPAddress = IPHelper.GetIPAddress, }); } } } catch (Exception e) { DisposeUserFriendlyException(e, ref json, "api/category/delete", LocalizationConst.DeleteFail); } return(json); }
public JsonResult Delete(int id) { _articlecategoryService.Delete(id); return(Json(1, JsonRequestBehavior.AllowGet)); }