internal void UpdateLogin(string email, string firstName, string lastName, bool active)
 {
     if (_context.PatientPortalLogins.Where(x => x.Email == email).Count() == 0)
     {
         throw new Exception("Not Found");
     }
     PatientPortalExtendedServices.UpdateLogin(email, firstName, lastName, active);
 }
        internal string ResetPassword(int loginID)
        {
            var membership = _context.PatientPortalLogins.Find(loginID).WebMembershipDetail;

            string pass = PatientPortalExtendedServices.GeneratePassword();

            membership.Password = pass;

            _context.SaveChanges();


            var smtpInfo = AppService.Current.DataContext.SMTPAccounts.Where(x => x.AccountName == "Primary").SingleOrDefault();

            if (smtpInfo == null)
            {
                throw new ArgumentNullException("Primary SMTP Account info has not been configured.");
            }
            var smtpAccount = new AABC.Domain.Email.SMTPAccount()
            {
                Username           = smtpInfo.AccountUsername,
                Password           = smtpInfo.AccountPassword,
                Server             = smtpInfo.AccountServer,
                Port               = smtpInfo.AccountPort.Value,
                UseSSL             = smtpInfo.AccountUseSSL.Value,
                AuthenticationMode = smtpInfo.AccountAuthMode.Value,
                FromAddress        = smtpInfo.AccountDefaultFromAddress,
                ReplyToAddress     = smtpInfo.AccountDefaultReplyAddress
            };

            string subject = "Applied Behavioral Parent Portal Account Password Reset";
            string message = "The password for your account on the Applied Behavioral Parent Portal has been reset. You can log in to your account at {0}\n\nUserName: {1}\nPassword: {2}";

            message = String.Format(message, AppService.Current.Settings.PatientPortalSite, membership.User.Email, pass);
            AABC.DomainServices.Email.SMTP.Send(smtpAccount, subject, message, membership.User.Email);


            return(pass);
        }
        internal string AddLogin(string email, string firstName, string lastName, bool active)
        {
            if (_context.PatientPortalLogins.Where(x => x.Email == email).Count() > 0)
            {
                return(null);
            }

            // EF6 add login is giving me errors about inserting IDs and I've spent enough time
            // trying to troubleshoot... will resort to manual creation here
            string password = PatientPortalExtendedServices.CreateLogin(email, firstName, lastName, active);

            var smtpInfo = AppService.Current.DataContext.SMTPAccounts.Where(x => x.AccountName == "Primary").SingleOrDefault();

            if (smtpInfo == null)
            {
                throw new ArgumentNullException("Primary SMTP Account info has not been configured.");
            }
            var smtpAccount = new AABC.Domain.Email.SMTPAccount()
            {
                Username           = smtpInfo.AccountUsername,
                Password           = smtpInfo.AccountPassword,
                Server             = smtpInfo.AccountServer,
                Port               = smtpInfo.AccountPort.Value,
                UseSSL             = smtpInfo.AccountUseSSL.Value,
                AuthenticationMode = smtpInfo.AccountAuthMode.Value,
                FromAddress        = smtpInfo.AccountDefaultFromAddress,
                ReplyToAddress     = smtpInfo.AccountDefaultReplyAddress
            };

            string subject = "Applied Behavioral Parent Portal Account Created";
            string message = "An account has been created for you on the Applied Behavioral Parent Portal. You can log in to your new account at {0}\n\nUserName: {1}\nPassword: {2}";

            message = String.Format(message, AppService.Current.Settings.PatientPortalSite, email, password);
            AABC.DomainServices.Email.SMTP.Send(smtpAccount, subject, message, email);

            return(password);
        }