public ActionResult Create(PersonViewModel person) { if (ModelState.IsValid) { var personRepo = _personRepo; var mapper = new PersonMapper(); var dto = mapper.MapPersonDto(person); personRepo.Add(dto); return RedirectToAction("Index"); } return View(); }
public PersonDto MapPersonDto(PersonViewModel person) { if (person == null) { return null; } var personDto = new PersonDto() { Id = person.Id, PersonName = person.Name, Surname = person.Surname, PhoneNumber = person.PhoneNumber, Email = person.Email, Photo = person.Photo }; return personDto; }
public ActionResult Edit(PersonViewModel item) { try { var map = new PersonMapper(); var personDto = map.MapPersonDto(item); _personRepo.Update(personDto); return RedirectToAction("Index"); } catch (Exception e) { var x = e; return View(); } }
public PersonViewModel MapPerson(PersonDto personDto) { if (personDto == null) { return null; } var person = new PersonViewModel() { Id = personDto.Id, Name = personDto.PersonName, Surname = personDto.Surname, Email = personDto.Email, PhoneNumber = personDto.PhoneNumber, Photo = personDto.Photo }; return person; }
private static PersonViewModel CreateValidPerson() { var person = new PersonViewModel() { Id = 1, Name = "Ntokozo", Surname = "Shagala", Email = "*****@*****.**", PhoneNumber = "0451254125", }; return person; }
public void Create_Post_GivenEmptyFields_ShouldRedirectToIndexView() { //---------------Set up test pack------------------- var controller = CreatePersonController(); var person = new PersonViewModel(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var actualView = controller.Create(person) as RedirectToRouteResult; //---------------Test Result ----------------------- Assert.IsNotNull(actualView); Assert.AreEqual("Index", actualView.RouteValues["action"]); }
public void Create_Post_GivenEmptyFields_ShouldNotAddAndReturnCreateView() { //---------------Set up test pack------------------- var controller = CreatePersonController(); var person = new PersonViewModel(); //---------------Assert Precondition---------------- //---------------Execute Test ---------------------- var actualView = controller.Create(person); //---------------Test Result ----------------------- Assert.IsNotNull(actualView); }
private static PersonViewModel CreatePerson() { var person = new PersonViewModel() { Id = 1, Name = "Ntokozo" }; return person; }