public PartialViewResult delete(int id) { var model = new BlogPostCategoryVm(); model.PostCategoriesList = entities.BlogPostCategories.ToList(); try { var details = entities.BlogPostCategories.Find(id); if (details == null) { TempData["ErrorMsg"] = "No data found"; return(PartialView("Blog_post_categories_partial", model)); } entities.BlogPostCategories.Remove(details); entities.SaveChanges(); TempData["SuccessMsg"] = "Category Removed successfully"; model.PostCategoriesList = entities.BlogPostCategories.ToList(); } catch (Exception) { TempData["ErrorMsg"] = "You can not remove this category"; } return(PartialView("Blog_post_categories_partial", model)); }
public ActionResult Index() { BlogPostCategoryVm model = new BlogPostCategoryVm(); model.PostCategoriesList = entities.BlogPostCategories.ToList(); return(View(model)); }
private List <BlogPostCategoryVm> CategoryListVm() { var categoryVmList = new List <BlogPostCategoryVm>(); var categoryList = _entities.BlogPostCategories.OrderByDescending(x => x.Id).ToList(); foreach (var cat in categoryList) { var categoryVm = new BlogPostCategoryVm(); categoryVm.Id = cat.Id; categoryVm.CategoryName = cat.CategoryName; categoryVm.IsChecked = false; categoryVmList.Add(categoryVm); } return(categoryVmList); }
public PartialViewResult create(BlogPostCategoryVm model) { model.PostCategoriesList = entities.BlogPostCategories.ToList(); if (ModelState.IsValid) { if (entities.BlogPostCategories.Where(x => x.CategoryName.ToLower().Trim() == model.CategoryName.ToLower().Trim()).Any()) { TempData["ErrorMsg"] = "There is already a Category on same name"; return(PartialView("Blog_post_categories_partial", model)); } BlogPostCategory category = new BlogPostCategory(); category.CategoryName = model.CategoryName; entities.BlogPostCategories.Add(category); entities.SaveChanges(); TempData["SuccessMsg"] = "Category created successfully"; model.PostCategoriesList = entities.BlogPostCategories.ToList(); } else { TempData["ErrorMsg"] = "Please enter Category name"; } return(PartialView("Blog_post_categories_partial", model)); }