コード例 #1
0
 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();
 }
コード例 #2
0
 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;
 }
コード例 #3
0
        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();
            }

        }
コード例 #4
0
        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;
        }
コード例 #5
0
 private static PersonViewModel CreateValidPerson()
 {
     var person = new PersonViewModel()
     {
         Id = 1,
         Name = "Ntokozo",
         Surname = "Shagala",
         Email = "*****@*****.**",
         PhoneNumber = "0451254125",
     };
     return person;
 }
コード例 #6
0
 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"]);
 }
コード例 #7
0
 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);
 }
コード例 #8
0
 private static PersonViewModel CreatePerson()
 {
     var person = new PersonViewModel() { Id = 1, Name = "Ntokozo" };
     return person;
 }