public void InsertOrUpdate(PairingUser pairinguser) { if (pairinguser.PairingUserId == default(int)) { // New entity context.PairingUsers.Add(pairinguser); } else { // Existing entity context.Entry(pairinguser).State = EntityState.Modified; } }
public ActionResult Create(PairingUser pairinguser) { if (!ModelState.IsValid) { return View(); } pairinguserRepository.InsertOrUpdate(pairinguser); pairinguserRepository.Save(); return RedirectToAction("Index"); }
public void CreatePairingUserTest() { // Arrange var pairingUser = new PairingUser(); var _repository = new Mock<IPairingUserRepository>(); var controller = new PairingUsersController(_repository.Object) { ControllerContext = new Mock<ControllerContext>().Object }; // Act var result = controller.Create(pairingUser) as ActionResult; // Assert Assert.IsNotNull(result, "Cannot Create PairingUser"); }