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);
            }
        }
        public void CreateMember(Dtos.CreateMemberInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            //ERROR:  Logger.Info("Creating a task for input: " + input);

            //Creating a new Task entity with given input's properties
            var member = new Member { 
                CellPhone = input.CellPhone,
                CompanyRefId = input.CompanyRefId,
                Credential = input.Credential,
                Email = input.Email,
                Fax = input.Fax,
                FullName = input.FullName,
                JobTitle = input.JobTitle,
                LicenseDescription = input.LicenseDescription,
                LicenseNumber = input.LicenseNumber,
                UserRefId = input.UserRefId,
                Phone = input.Phone
            };

            //Saving entity with standard Insert method of repositories.
            _memberRepository.Insert(member);
        }
        public virtual async Task<CreditsHero.Subscribers.Dtos.SubscribersDto> RegisterCreditsHero(Member subscriber)
        {
            CreditsHero.Subscribers.Dtos.SubscribersDto subscriberResponse = new CreditsHero.Subscribers.Dtos.SubscribersDto();

            try
            {
                var creditsHeroFormat = String.Format("{0}api/services/app/Subscriber/CreateSubscribers", WebConfigurationManager.AppSettings["creditsHero:WebServiceApiPrefix"]);
                //var creditsHeroFormat = "http://creditshero.azurewebsites.net/api/services/cd/Subscriber/CreateSubscribers";
                //var creditsHeroFormat = "http://localhost:6234/api/services/cd/Subscriber/CreateSubscribers"; //DEBUG
                var timelineUrl = string.Format(creditsHeroFormat);
                
                //Serialize object to JSON
                MemoryStream jsonStream = new MemoryStream();
                CreditsHero.Subscribers.Dtos.CreateSubscribersInput subscriberInput = new CreditsHero.Subscribers.Dtos.CreateSubscribersInput()
                {
                    Email = subscriber.Email,
                    FullName = subscriber.FullName,
                    SmsNumber = subscriber.CellPhone,
                    SubscribersId = 0
                };
                string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(subscriberInput);
                byte[] byteArray = Encoding.UTF8.GetBytes(jsonData);
                    //string.Format("{{subscribersId: null; fullName: '{0}', smsNumber: '{1}', email: '{2}'}}", subscriber.FullName, subscriber.CellPhone, subscriber.Email));

                HttpWebRequest creditsHeroRequest = (HttpWebRequest)WebRequest.Create(timelineUrl);
                creditsHeroRequest.ContentType = "application/json;charset=utf-8";
                creditsHeroRequest.ContentLength = byteArray.Length;
                creditsHeroRequest.Method = "POST";
                Stream newStream = creditsHeroRequest.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);
                newStream.Close();
                WebResponse timeLineResponse = creditsHeroRequest.GetResponse();
                var timeLineJson = string.Empty;
                using (timeLineResponse)
                {
                    using (var reader = new StreamReader(timeLineResponse.GetResponseStream()))
                    {
                        var results = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(reader.ReadToEnd());
                        subscriberResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<CreditsHero.Subscribers.Dtos.SubscribersDto>(results.result.ToString());
                    }
                }

                return subscriberResponse;
            }
            catch (UserFriendlyException ex)
            {
                ViewBag.ErrorMessage = ex.Message;
                return subscriberResponse;
            }
        }