public void InsertOrUpdate(User user) { if (user.Id == default(int)) { // New entity context.Users.Add(user); } else { // Existing entity context.Entry(user).State = EntityState.Modified; } }
public JsonResult Create(User userIn) { if (ModelState.IsValid) { userRepository.InsertOrUpdate(userIn); userRepository.Save(); // return RedirectToAction("Index"); } //else { //// } return Json(userRepository.AllIncluding(user => user.UserLocations, user => user.UserRoles), JsonRequestBehavior.AllowGet); }