public ActionResult Index([Bind(Include =
                                     "ContactFirstName, ContactLastName, MobilePhone, BirthDay, JobTitle,Email")] ContactEntityModel contactModel)
 {
     if (ModelState.IsValid)
     {
         var contactHelper = new DalContactEntity();
         contactHelper.AddContactToCrm(contactModel);
         var resultmessage = string.Format("Контакт \"{0} {1}\" сохранен.", contactModel.ContactFirstName, contactModel.ContactLastName);
         return(RedirectToAction("Index", new { result = resultmessage }));
     }
     return(View(contactModel));
 }
        /// <summary>
        /// Метод создает новую запись сущности "contact".
        /// </summary>
        /// <param name="contactModel">Объект модели контакта.</param>
        public void AddContactToCrm(ContactEntityModel contactModel)
        {
            // Получаем токен.
            var token = new CrmAuthenticationToken
            {
                AuthenticationType = 0,
                OrganizationName   = "AdventureWorksCycle"
            };

            var connectionString = System.Configuration.ConfigurationManager.
                                   ConnectionStrings["CrmConnection"].ConnectionString;

            // Получаем сервис организации CRM.
            var service = new CrmService
            {
                Url = connectionString,
                CrmAuthenticationTokenValue = token,
                Credentials = System.Net.CredentialCache.DefaultCredentials
            };

            // Создаем новую запись.
            var newContact = new contact
            {
                firstname     = contactModel.ContactFirstName,
                lastname      = contactModel.ContactLastName,
                mobilephone   = contactModel.MobilePhone,
                emailaddress1 = contactModel.Email,
                jobtitle      = contactModel.JobTitle
            };

            if (contactModel.BirthDay.HasValue)
            {
                newContact.birthdate = CrmDateTime.FromUser(contactModel.BirthDay.Value);
            }

            service.Create(newContact);
        }