public void ProcessResponseToSignupInvite(TxtMsgInbound msgInbound, TxtMsgAwaitingResponse awaiting, AppUser user)
        {
            MessageAffirmativeType affirmativeType = MessageUtility.ParseAffirmativeType(msgInbound);
            string feedback = null;
            Parent parent = _parentRepository.GetById(awaiting.ParentId, true);
            if (parent == null)
                throw new Exception("Error while processing inbound message. Parent not found with ID" + awaiting.ParentId);
            // If user answers 'yes'.
            if (affirmativeType == MessageAffirmativeType.yes)
            {
                // If user already exists we simply add hib to parent's sitterhub.
                if (user != null)
                {
                    if (user.UserRole == UserRole.Sitter)
                    {
                        // ..sure if this user is a sitter.
                        AddSitterToParentMySitters(user.Id, parent, msgInbound.MobilePhone);
                        feedback = MessageTemplates.FormatUserAddedToSitters(parent);
                    }
                    else
                    {
                        // Otherwise we cannot add user because he is not a sitter.
                        feedback = MessageTemplates.FormatInvitedUserIsNotASitter();
                    }
                }
                    // If user doesn't exist we need to create new one.
                else
                {
                    // Create new (default) sitter profile.
                    var newSitter = new SignupInfo
                    {
                        User = new AppUser
                        {
                            FirstName = "New Sitter",
                            LastName = "",
                            Email = "",
                            MobilePhone = msgInbound.MobilePhone,
                            UserRole = UserRole.Sitter,
                        },
                        Pass = GeneratePassForNewUser() //FutureDev: text this password to sitter as their new temp password.
                    };
                    newSitter.SitterSignupInfo = new SitterSignupInfo {ParentEmail = "", ParentMobile = ""};

                    SignupResult result = new SignupRepository().SaveNewSignup(newSitter, false, false);
                    if (!result.IsSuccess)
                        throw new Exception("Failed to create new profile for sitter during parent invite." + result.Error);
                    // If there were no errors we can continue.
                    // We need to add newly created user into parent's sitterhub.
                    AddSitterToParentMySitters(result.NewId, parent, msgInbound.MobilePhone);
                    // Send message about new account created and user successfully added to parent's hub.
                    feedback = MessageTemplates.FormatUserAddedToSittersAndProfileCreated(parent, newSitter.Pass);
                }
            }
                // If user answered 'no'.
            else if (affirmativeType == MessageAffirmativeType.no)
            {
                // TODO: separate failure message.
                // We send message to sitter that we didn't added him to parent's hub.
                feedback = MessageTemplates.FormatDeclineInvitationToSitterhub(parent);
                _parentRepository.CancelInviteSitter(parent.Id, msgInbound.MobilePhone, true);
            }
                // If user's answer can't be parsed.
            else
            {
                feedback = MessageTemplates.FormatSitterInvalidResponseToJobOrSignup(false);
            }
            // Update state of message.
            _txtMsgInboundDal.UpdateState(msgInbound.Id, TxtMsgProcessState.Processed);
            // If sitter's answer was successfully parsed we can mark this message as processed.
            if (affirmativeType != MessageAffirmativeType.Unknown)
            {
                _txtMsgAwaitingResponseDal.DeleteAwaiting(awaiting.Id);
            }
            // TODO: where we send messages to parent? Seems like we can do it here.
            if (feedback != null)
            {
                _omm.SendFeedbackToInboundMessage(msgInbound, feedback, user.Id);
            }
        }
        public void ProcessSelfSignupConversation_Step1(TxtMsgInbound msgInbound, TxtMsgAwaitingResponse awaiting, AppUser user)
        {
            bool deleteAwaiting = true;
            if (MessageUtility.IsCancelRequested(msgInbound))
            {
                _omm.SendFeedbackToInboundMessage(msgInbound, "Ok, signup cancelled", user.Id);
            }
            else if (msgInbound.Message == "sitter" || msgInbound.Message == "parent" || msgInbound.Message == "babysitter")
            {
                bool isSitter = (msgInbound.Message == "sitter" || msgInbound.Message == "babysitter");
                // STEP - Create new AppUser
                var newUser = new SignupInfo
                {
                    User = new AppUser
                    {
                        FirstName = "New Self Signup",
                        LastName = "",
                        Email = "",
                        MobilePhone = msgInbound.MobilePhone,
                        UserRole = isSitter ? UserRole.Sitter : UserRole.Parent,
                    },
                    Pass = GeneratePassForNewUser()
                };
                if (isSitter)
                {
                    newUser.SitterSignupInfo = new SitterSignupInfo {ParentEmail = "", ParentMobile = ""};
                }

                SignupResult result = new SignupRepository().SaveNewSignup(newUser, false);
                if (result.IsSuccess)
                {
                    _omm.SendFeedbackToInboundMessage(msgInbound, string.Format("Ok, you have signed up for mysitterhub.com, you can login at mysitterhub.com with your mobile number and password: {0}.", newUser.Pass), user.Id);
                    //_omm.SendFeedbackToInboundMessage(msgInbound, string.Format("You can finish filling out your profile. What is your name? Or say 'cancel'."));
                    //_txtMsgAwaitingResponseDal.Insert(new TxtMsgAwaitingResponse(outboundTxtMsgId, 0, msgInbound.MobilePhone, InboundMessageType.SelfSignup_Step2_Name, 0)); //FutureDev
                }
                else
                {
                    _omm.SendFeedbackToInboundMessage(msgInbound, string.Format("Error while signing up:" + result.Error), user.Id);
                    new LogUtil().LogMessage("signup unsuccessful " + result.Error);
                    deleteAwaiting = false;
                }
            }
            else
            {
                _omm.SendFeedbackToInboundMessage(msgInbound, string.Format("Invalid response, are you a 'parent' or a 'sitter'? Or say 'cancel' to quit the signup process."), user.Id);
                deleteAwaiting = false;
            }

            if (deleteAwaiting)
                _txtMsgAwaitingResponseDal.DeleteAwaiting(awaiting.Id);
        }