public ActionResult Create(CustomerProfile customerprofile) { if (ModelState.IsValid) { customerprofileRepository.InsertOrUpdate(customerprofile); customerprofileRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(CustomerProfile customerprofile) { if (customerprofile.CustomerProfileId == default(int)) { // New entity context.CustomerProfiles.Add(customerprofile); } else { // Existing entity context.Entry(customerprofile).State = EntityState.Modified; } }