/// <summary>
 /// GET: /Company/{id}/Contact/{contactId}/Edit
 /// </summary>
 /// <param name="id"></param>
 /// <param name="contactId"></param>
 /// <returns></returns>
 public ActionResult Edit(int id, int? contactId)
 {
     if (contactId == null)
     {
         return View("Create");
     }
     Contact contact = db.Contacts.Find(contactId);
     if (contact == null || contact.Company.Id != id)
     {
         return HttpNotFound();
     }
     ContactVM model = new ContactVM();
     model = model.contactToViewModel(contact);
     ModelState.Clear();
     return View(model);
 }
Esempio n. 2
0
        public Contact viewModelToContact(ContactVM model)
        {
            Contact contact = new Contact
            {
                Id = model.Id,
                FirstName = model.FirstName,
                LastName = model.LastName,
                DateLastContacted = model.DateLastContacted,
                DateCreated = model.DateCreated,
                DateModified = model.DateModified
            };

            ICollection<Address> addressList = new List<Address>();
            foreach (AddressVM address in model.Addresses)
            {
                addressList.Add(address.viewModelToAddress(address));
            }
            contact.Addresses = addressList;

            ICollection<Email> emailList = new List<Email>();
            foreach (EmailVM emails in model.EmailAddresses)
            {
                emailList.Add(emails.viewModelToEmail(emails));
            }
            contact.EmailAddresses = emailList;

            ICollection<Phone> phoneList = new List<Phone>();
            foreach (PhoneVM phoneNumbers in model.PhoneNumbers)
            {
                phoneList.Add(phoneNumbers.viewModelToPhone(phoneNumbers));
            }
            contact.PhoneNumbers = phoneList;

            return contact;
        }
        /// <summary>
        /// GET: /Company/{id}/Contact/{contactId}
        /// </summary>
        /// <param name="id"></param>
        /// <param name="contactId"></param>
        /// <returns></returns>
        public ActionResult Details(int id, int? contactId)
        {
            ContactVM model = new ContactVM();

            if (contactId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            Contact contact = db.Contacts.Find(contactId);
            if (contact == null || contact.Company.Id != id)
            {
                return HttpNotFound();
            }

            model = model.contactToViewModel(contact);
            model.Addresses = GetAddresses((int)contactId);
            model.EmailAddresses = GetEmailAddresses((int)contactId);
            model.PhoneNumbers = GetPhoneNumbers((int)contactId);

            return View(model);
        }
Esempio n. 4
0
        public ContactVM contactToViewModel(Contact contact)
        {
            ContactVM model = new ContactVM
            {
                Id = contact.Id,
                CompanyId = contact.Company.Id,
                FirstName = contact.FirstName,
                LastName = contact.LastName,
                DateLastContacted = contact.DateLastContacted,
                DateCreated = contact.DateCreated,
                DateModified = contact.DateModified
            };

            return model;
        }