public IActionResult DeleteCategory(int id) { // Find the identity user var user = _userSettingRepo.Read(User.Identity.Name); // When there will be at least one news category setting if one is deleted if (user.UserSettingNewsCategories.Count() >= 2) { // Delete the supplied news category _newsCategoryRepo.Delete(id, user); } return(RedirectToAction("Index", "Profile")); }
private void EditCategoryForNews(AddNewsModel newsModel) { var selectedNewsCategory = _newsCategoryRepository.GetAll().Where(c => c.NewsId == newsModel.Id).ToList(); foreach (var item in selectedNewsCategory) { _newsCategoryRepository.Delete(item); } if (newsModel.SelectedCategory != null) { foreach (var item in newsModel.SelectedCategory) { _newsCategoryRepository.Add(new NewsCategory { NewsId = newsModel.Id, CategoryId = item }); } } }