public void InsertOrUpdate(Tag tag) { if (tag.TagId == default(int)) { // New entity context.Tags.Add(tag); } else { // Existing entity context.Entry(tag).State = EntityState.Modified; } }
public ActionResult Create(Tag tag) { if (ModelState.IsValid) { tagRepository.InsertOrUpdate(tag); tagRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleLinks = linkRepository.All; return View(); } }