public RegisterMemberViewModel()
 {
     Company = new Company();
 }
        public virtual async Task<ActionResult> RegisterMember(RegisterMemberViewModel model)
        {
            try
            {
                //Create Company
                var company = new Company
                {
                    Address1 = model.Company.Address1,
                    Address2 = model.Company.Address2,
                    City = model.Company.City,
                    Name = model.Company.Name,
                    ServiceArea = model.Company.ServiceArea,
                    State = model.Company.State,
                    YearEstablished = model.Company.YearEstablished,
                    Zip = model.Company.Zip
                };

                int companyId = await _companyManager.InsertAndGetIdAsync(company);

                //Create Member
                var member = new Member
                {
                    CellPhone = model.CellPhone,
                    CompanyRefId = companyId,
                    Credential = model.Credential,
                    Email = model.Email,
                    Fax = model.Fax,
                    FullName = model.FullName,
                    JobTitle = model.JobTitle,
                    LicenseDescription = model.LicenseDescription,
                    LicenseNumber = model.LicenseNumber,
                    UserRefId = model.UserRefId
                };

                int memberId = await _memberManager.InsertAndGetIdAsync(member);


                //Call CreditsHero Subscriber
                var subscriberResponse = await RegisterCreditsHero(member);

                //Call CreditsHero Get Criteria List for RooferLocator
                var roofTypes = _roofTypeService.GetRoofTypes(new CreditsHero.Common.Dtos.GetCriteriaInput()
                {
                    CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:CompanyId"]),
                    CriteriaId = 0
                });

                //Call CreditsHero Get Criteria List for RooferLocator
                var serviceTypes = _serviceTypeService.GetServiceTypes(new CreditsHero.Common.Dtos.GetCriteriaInput()
                {
                    CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:CompanyId"]),
                    CriteriaId = 0
                });
                
                //CreditsHero.Common.Dtos.GetCriteriaValuesOutput criteriaValues = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput();
                var roofTypeCriteriaValues = roofTypes.RoofTypes.Cast<CreditsHero.Common.Dtos.CriteriaValuesDto>().ToList();
                var serviceTypeCriteriaValues = serviceTypes.ServiceTypes.Cast<CreditsHero.Common.Dtos.CriteriaValuesDto>().ToList();

                RegisterCreditsHeroViewModel subscriberCriteriaModel = new RegisterCreditsHeroViewModel()
                {
                    RoofTypeCriteria = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput() { CriteriaValues = roofTypeCriteriaValues },
                    ServiceTypeCriteria = new CreditsHero.Common.Dtos.GetCriteriaValuesOutput() { CriteriaValues = serviceTypeCriteriaValues },
                    SubscriberEmail = subscriberResponse.Email,
                    SubscriberName = subscriberResponse.FullName,
                    SubscriberSms = subscriberResponse.SmsNumber,
                    SuscriberId = subscriberResponse.Id
                };

                //Send Email Notification to Administrator
                var serviceUrl = String.Format("{0}api/services/app/Notification/SendEmailNotification", WebConfigurationManager.AppSettings["creditsHero:WebServiceApiPrefix"]);
                //var serviceUrl = string.Format("http://CreditsHero.azurewebsites.net/api/services/cd/Notification/SendEmailNotification");
                CreditsHero.Messaging.Dtos.NotificationInput emailInput = new CreditsHero.Messaging.Dtos.NotificationInput();

                //Serialize object to JSON
                MemoryStream jsonStream2 = new MemoryStream();

                emailInput = new CreditsHero.Messaging.Dtos.NotificationInput()
                {
                    CompanyId = Guid.Parse(System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:APIKey"]),
                    EmailFrom = "*****@*****.**",
                    EmailSubject = String.Format("New Subscriber at RooferLocator.com"),
                    EmailMessage = String.Format("Hello Administrator: \n  A subscriber has been submitted at RooferLocator.com.\n\n Following are the Subscribers details:\n\n User Details \n\n FullName = {0} \n Email = {1} \n SMS Number (Cell Phone) = {2} \n\n  Company Details \n\n Company Name = {3} \n State = {4} \n City = {5}",
                        member.FullName,
                        member.Email,
                        member.CellPhone,
                        company.Name,
                        company.State,
                        company.City),
                    EmailTo = System.Web.Configuration.WebConfigurationManager.AppSettings["creditsHero:AdminEmailAddress"]
                };

                string jsonData2 = Newtonsoft.Json.JsonConvert.SerializeObject(emailInput);
                byte[] byteArray2 = Encoding.UTF8.GetBytes(jsonData2);

                HttpWebRequest serviceUrlRequest = (HttpWebRequest)WebRequest.Create(serviceUrl);
                serviceUrlRequest.ContentType = "application/json;charset=utf-8";
                serviceUrlRequest.ContentLength = byteArray2.Length;
                serviceUrlRequest.Method = "POST";
                Stream newStream2 = serviceUrlRequest.GetRequestStream();
                newStream2.Write(byteArray2, 0, byteArray2.Length);
                newStream2.Close();
                WebResponse timeLineResponse2 = serviceUrlRequest.GetResponse();
                using (timeLineResponse2)
                {
                    using (var reader = new StreamReader(timeLineResponse2.GetResponseStream()))
                    {
                        var results = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd());

                        Newtonsoft.Json.Linq.JObject jObject2 = results.result;
                        var itemResult = Newtonsoft.Json.JsonConvert.DeserializeObject<CreditsHero.Messaging.Requests.Dtos.GetInquiryResults>(jObject2.ToString());
                    }
                }

                return View("RegisterCreditsHero", subscriberCriteriaModel);
                
                //return Redirect(Url.Action("Index", "Home"));
            }
            catch (UserFriendlyException ex)
            {
                ViewBag.ErrorMessage = ex.Message;
                return View("Register", model);
            }
        }