public void InsertOrUpdate(ForumCategory forumcategory) { if (forumcategory.ForumCategoryID == default(int)) { // New entity _context.ForumCategory.Add(forumcategory); } else { // Existing entity _context.Entry(forumcategory).State = EntityState.Modified; } }
public ActionResult CreateForum(ForumCategory model) { if (_mu == null) return RedirectToAction("Index"); var ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey)); if (!ua.IsAdmin) throw new UnauthorizedAccessException(); using (var context = new DasKlubDbContext()) { if (model == null) return RedirectToAction("Index"); model.CreatedByUserID = ua.UserAccountID; model.Key = FromString.UrlKey(model.Title); model.Title = model.Title.Trim(); model.Description = model.Description.Trim(); context.ForumCategory.Add(model); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult EditForum(ForumCategory model) { if (_mu == null) return RedirectToAction("Index"); var ua = new UserAccount(Convert.ToInt32(_mu.ProviderUserKey)); if (!ua.IsAdmin) throw new UnauthorizedAccessException(); using (var context = new DasKlubDbContext()) { if (model == null) return RedirectToAction("Index"); ForumCategory forumCategory = context.ForumCategory.First(x => x.ForumCategoryID == model.ForumCategoryID); forumCategory.CreatedByUserID = ua.UserAccountID; forumCategory.Key = FromString.UrlKey(model.Title); forumCategory.Title = model.Title.Trim(); forumCategory.Description = model.Description.Trim(); context.Entry(forumCategory).State = EntityState.Modified; context.SaveChanges(); } return RedirectToAction("Index"); }