public ActionResult Edit(Demographic viewModel) { if (SaveDemographic(viewModel)) return RedirectToAction("index"); else return View(viewModel); }
public virtual void Save(Demographic viewModel) { viewModel.HomeContact.Country = AppConstant.COUNTRY; viewModel.HomeContact.ContactType = AppConstant.CONTACT_TYPE; viewModel.HomeContact.MemberID = viewModel.Member.MemberID; TheUnitOfWork.MemberRepository.Save(viewModel.Member); TheUnitOfWork.ContactRepository.Save(viewModel.HomeContact); TheUnitOfWork.Save(); }
public void test_demographic_creation() { //Arrange DemographicController demoController = GetDemographicControllerObject(); ViewResult resultBefore = demoController.Index() as ViewResult; int countBefore = ((List<Demographic>)resultBefore.Model).Count; Contact contact = new Contact { AddressLine1 = "123 randolph drive", AddressLine2 = "Apt 1", City = "Madison", StateID = "IL", ZipCode = "68717", Email = "*****@*****.**" }; Demographic demographic = new Demographic { Member = new Member { FirstName = "John-" + DateTime.Now.Date.ToShortDateString(), LastName = "Doe", Contacts = new List<Contact> { contact } }, HomeContact = contact }; //Act demoController.Create(demographic); //Assert ViewResult resultAfter = demoController.Index() as ViewResult; int countAfter = ((List<Demographic>)resultAfter.Model).Count; Assert.AreEqual(countAfter, countBefore + 1); }
private bool SaveDemographic(Demographic viewModel) { try { _demographicService.Save(viewModel); return true; } catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException) { ModelState.AddModelError(string.Empty, "Record is updated by another user, please reload and try again."); } catch (Exception ex) { ModelState.AddModelError(string.Empty,ex.Message); } viewModel.StateList = GetStateList(); return false; }
public ActionResult Create() { Demographic viewModel = new Demographic(); viewModel.StateList = GetStateList(); return View(viewModel); }