public ActionResult Create(ChartType charttype) { if (ModelState.IsValid) { charttypeRepository.InsertOrUpdate(charttype); charttypeRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(ChartType charttype) { if (charttype.Key == default(string)) { // New entity context.ChartType.Add(charttype); } else { // Existing entity context.ChartType.Attach(charttype); context.Entry(charttype).State = EntityState.Modified; } }