public ActionResult Create()
        {
            ContactModel viewModel = new ContactModel();
              viewModel.Countries = BuildCountryList("");

              return View("Create", viewModel);
        }
        public ActionResult Create(ContactModel model)
        {
            if (!ModelState.IsValid) {
            return View();
              }

              try {
            saveNewContact(model);

            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = "Contact was successfully created.";

            return RedirectToAction("Index");

              } catch (Exception ex) {
            StringBuilder errMsg = new StringBuilder();
            errMsg.Append("Unable to create " + model.Company + ", " + model.FirstName + " " + model.LastName + ". " + ex.Message);
            log.Error(errMsg.ToString());
            TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = errMsg.ToString();
            return View();
              }
        }
        private Contact UpdateContactFromModel(Contact contact, ContactModel model)
        {
            contact.Company = model.Company == null ? "" : model.Company;
              contact.FirstName = model.FirstName == null ? "" : model.FirstName;
              contact.LastName = model.LastName == null ? "" : model.LastName;
              contact.Gender = model.Gender == null ? "" : model.Gender;
              contact.Address1 = model.Address1 == null ? "" : model.Address1;
              contact.Address2 = model.Address2 == null ? "" : model.Address2;
              contact.City = model.City == null ? "" : model.City;
              contact.State = model.State == null ? "" : model.State;
              contact.PostalCode = model.PostalCode == null ? "" : model.PostalCode;
              contact.CellPhone = model.CellPhone == null ? "" : model.CellPhone;
              contact.HomePhone = model.HomePhone == null ? "" : model.HomePhone;
              contact.WorkPhone = model.WorkPhone == null ? "" : model.WorkPhone;
              contact.Email = model.Email == null ? "" : model.Email;
              contact.Birthday = model.Birthday;
              contact.Notes = model.Notes;

              return contact;
        }
        private void saveNewContact(ContactModel model)
        {
            this.user = userServices.FindUser(this.User.Identity.Name);
              Contact contact = new Contact();
              contact = UpdateContactFromModel(contact, model);
              contact.User = this.user;
              contact.Created = DateTime.Now;
              contact.LastModified = DateTime.Now;
              contactServices.Save(contact);

              if (model.isDiver) {
            Diver diver = new Diver();
            diver.Contact = contact;
            diverServices.Save(diver);
              }
              if (model.isInstructor) {
            Instructor instructor = new Instructor();
            instructor.Contact = contact;
            instructorServices.Save(instructor);
              }

              if (model.isAgency) {
            DiveAgency agency = new DiveAgency();
            agency.Contact = contact;
            diveAgencyServices.Save(agency);
              }

              if (model.isManufacturer) {
            Manufacturer manufacturer = new Manufacturer();
            manufacturer.Contact = contact;
            manufacturerServices.Save(manufacturer);
              }

              if (model.isDiveShop)
              {
            DiveShop diveShop = new DiveShop();
            diveShop.Contact = contact;
            diveShopServices.Save(diveShop);
              }
        }
        public ActionResult Edit(int id, ContactModel model)
        {
            try {
            Contact contact = contactServices.GetContact(id);
            contact = UpdateContactFromModel(contact, model);
            contactServices.Save(contact);

            return RedirectToAction("Index");
              } catch {
            return View();
              }
        }
        public ActionResult Edit(int id)
        {
            ContactModel model = new ContactModel();
              Contact contact = contactServices.GetContact(id);
              model.Address1 = contact.Address1;
              model.Address2 = contact.Address2;
              model.City = contact.City;
              model.Company = contact.Company;
              model.ContactId = contact.Id;
              model.Email = contact.Email;
              model.FirstName = contact.FirstName;
              model.LastName = contact.LastName;
              model.Notes = contact.Notes;
              model.PostalCode = contact.PostalCode;
              model.State = contact.State;

              return View("Edit", model);
        }