public ActionResult Edit(ContactCreateViewModel contactvmNew, HttpPostedFileBase file) { try { Contact _con = ContactsMapper.To_Contact_Create_ViewModel(contactvmNew); if (file != null) { string _FileName = Path.GetFileName(file.FileName); string _path = Path.Combine(Server.MapPath("~/UploadImg"), _FileName); _con.ImagePath = _FileName; file.SaveAs(_path); } else { _con.ImagePath = "images.png"; } _contactrepository.Update(_con); _contactrepository.Save(); List <PhoneNumber> _phonenumber = PhoneNumberMapper.To_PhoneNumber_Create_ViewModel(contactvmNew, _con.ContactId).ToList(); foreach (PhoneNumber phonItem in _phonenumber) { _phonenumberrepository.Update(phonItem); _phonenumberrepository.Save(); } return(RedirectToAction("Contacts")); } catch (DataException) { ModelState.AddModelError(string.Empty, "Unable to save changes. Try again."); } return(View(contactvmNew)); }
public void convertDtoToEntityHappyPathTest() { //arrange var mapper = new ContactsMapper(); //act var actual = mapper.convertEntityToDTO(contactsEntity); //assert Assert.AreEqual(contactResponseDTO.name.first, actual.name.first); Assert.AreEqual(contactResponseDTO.name.middle, actual.name.middle); Assert.AreEqual(contactResponseDTO.name.last, actual.name.last); Assert.AreEqual(contactResponseDTO.email, actual.email); }
public ActionResult Create(ContactsMapper mContact) { IMapper mapper = AutoMapperInitializer.getMapper(); var contact = mapper.Map <Contacts>(mContact); var back = mapper.Map <ContactsMapper>(contact); var dataContext = new PetaPoco.Database("sqladdress"); dataContext.Insert(contact); return(RedirectToAction("Index")); }
// GET: PhoneBookHomeController/Edit public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Contact _contact = _contactrepository.Select(id); List <PhoneNumber> _phonenumberlist = _phonenumberrepository.SelectAll().Where(d => d.ContactId == _contact.ContactId).ToList(); ContactCreateViewModel contactVM = PhoneNumberMapper.To_Contact_Create_ViewModel(_phonenumberlist); contactVM.contactvm = ContactsMapper.To_Contact_View_Model(_contact); if (contactVM == null) { return(HttpNotFound()); } return(View(contactVM)); }
public void convertRequestToEntityHappyPathTest() { //arrange var mapper = new ContactsMapper(); ContactRequestDTO request = new ContactRequestDTO { name = name, address = address, phone = phones, email = "*****@*****.**" }; //act var actual = mapper.convertRequestToEntity(request); //assert Assert.AreEqual(contactsEntity.first, actual.first); Assert.AreEqual(contactsEntity.middle, actual.middle); Assert.AreEqual(contactsEntity.last, actual.last); Assert.AreEqual(contactsEntity.email, actual.email); }
public ActionResult Create(ContactCreateViewModel contactcreatevm, HttpPostedFileBase file) { if (ModelState.IsValid) { Contact _contact = ContactsMapper.To_Contact_Create_ViewModel(contactcreatevm); try { if (file.ContentLength > 0) { string _FileName = Path.GetFileName(file.FileName); string _path = Path.Combine(Server.MapPath("~/UploadImg"), _FileName); _contact.ImagePath = _FileName; file.SaveAs(_path); } } catch { _contact.ImagePath = "images.png"; } finally { int val = 0; _contactrepository.Create(_contact, ref val); _contactrepository.Save(); List <PhoneNumber> _phonenumber = PhoneNumberMapper.To_PhoneNumber_Create_ViewModel(contactcreatevm, val).ToList(); foreach (PhoneNumber phonItem in _phonenumber) { _phonenumberrepository.Create(phonItem); _phonenumberrepository.Save(); } } return(RedirectToAction("Contacts")); } return(View("Create")); }
public ContactsController(IUserProvider userProvider, ContactsMapper contactsMapper) { _userProvider = userProvider; _contactsMapper = contactsMapper; }