public void InsertOrUpdate(Expert expert) { if (expert.Id == default(int)) { // New entity context.Experts.Add(expert); } else { // Existing entity context.Entry(expert).State = EntityState.Modified; } }
public ActionResult Create(Expert expert) { if (ModelState.IsValid) { expertRepository.InsertOrUpdate(expert); expertRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleGroups = groupRepository.All; return View(); } }