internal InstitutionModel GetInstitutionDetails(InstitutionModel institutionModel)
        {
            try
            {
                //Demo purposes only.  The OAuth tokens returned by the SAML assertion are valid for 1 hour and do not need to be requested before each API call.
                SamlRequestValidator validator = new SamlRequestValidator(AggCatAppSettings.Certificate,
                                                                          AggCatAppSettings.ConsumerKey,
                                                                          AggCatAppSettings.ConsumerSecret,
                                                                          AggCatAppSettings.SamlIdentityProviderId,
                                                                          AggCatAppSettings.CustomerId);
                ServiceContext ctx = new ServiceContext(validator);
                AggregationCategorizationService svc = new AggregationCategorizationService(ctx);
                institutionModel.InstitutionDetail = svc.GetInstitutionDetails(institutionModel.InstitutionId);
                institutionModel.Success = true;
                institutionModel.Error = null;
            }
            catch (AggregationCategorizationException ex)
            {
                institutionModel.InstitutionDetail = null;
                institutionModel.Success = false;
                institutionModel.Error = ex.ToString();
            }

            return institutionModel;
        }
        public InstitutionModel GetDefaultInstitutions()
        {
            InstitutionModel model = new InstitutionModel();

            //Demo purposes only.  The OAuth tokens returned by the SAML assertion are valid for 1 hour and do not need to be requested before each API call.
            SamlRequestValidator validator = new SamlRequestValidator(AggCatAppSettings.Certificate,
                                                                      AggCatAppSettings.ConsumerKey,
                                                                      AggCatAppSettings.ConsumerSecret,
                                                                      AggCatAppSettings.SamlIdentityProviderId,
                                                                      AggCatAppSettings.CustomerId);
            ServiceContext ctx = new ServiceContext(validator);
            AggregationCategorizationService svc = new AggregationCategorizationService(ctx);
            try
            {
                List<Institution> institutions = svc.GetInstitutions().institution.ToList<Institution>();
                model.Institutions = institutions;
                model.Error = null;
                model.Success = true;
            }
            catch (AggregationCategorizationException ex)
            {
                model.Institutions = null;
                model.Error = ex.ToString();
                model.Success = false;
            }

            return model;
        }
        public ActionResult Index(InstitutionModel institutionModel)
        {
            InstitutionModel model = this.serviceOperations.GetInstitutionDetails(institutionModel);
            if (model.Institutions == null)
            {
                model.Institutions = Session["Institutions"] as List<Institution>;
            }

            return View(model);
        }
        public ActionResult Index()
        {
            InstitutionModel model = null;
            if (Session["Institutions"] == null)
            {
                model = this.serviceOperations.GetDefaultInstitutions();
                Session["Institutions"] = model.Institutions;
            }
            else
            {
                model = new InstitutionModel { Institutions = Session["Institutions"] as List<Institution>, Error = null, Success = true };
            }

            return View(model);
        }
 public ActionResult DiscoverAndAddLogin(InstitutionModel model)
 {
     model.InstitutionDetail = Session["InstitutionDetail"] as InstitutionDetail;
     DiscoverAddModel discoverModel = this.serviceOperations.DiscoverAndAdd(model);
     Session["DAM"] = discoverModel;
     if (discoverModel.MFA)
     {
         Session.Remove("InstitutionDetail");
         return RedirectToAction("DiscoverAndAddChallenge", "Institutions");
     }
     else
     {
         Session.Remove("InstitutionDetail");
         return RedirectToAction("DiscoverAndAddResult", "Institutions");
     }
 }
        internal DiscoverAddModel DiscoverAndAdd(InstitutionModel institutionModel)
        {
            DiscoverAddModel discoverAddModel = new DiscoverAddModel();
            try
            {

                //Demo purposes only.  The OAuth tokens returned by the SAML assertion are valid for 1 hour and do not need to be requested before each API call.
                SamlRequestValidator validator = new SamlRequestValidator(AggCatAppSettings.Certificate,
                                                                          AggCatAppSettings.ConsumerKey,
                                                                          AggCatAppSettings.ConsumerSecret,
                                                                          AggCatAppSettings.SamlIdentityProviderId,
                                                                          AggCatAppSettings.CustomerId);
                ServiceContext ctx = new ServiceContext(validator);
                AggregationCategorizationService svc = new AggregationCategorizationService(ctx);

                InstitutionLogin instLogin = new InstitutionLogin();
                Credentials creds = new Credentials();
                List<Credential> credentials = new List<Credential>();
                Credential cred = new Credential();
                cred.name = institutionModel.InstitutionDetail.keys.FirstOrDefault(k => k.displayOrder == 1).name;
                cred.value = institutionModel.Value1;
                credentials.Add(cred);

                cred = new Credential();
                cred.name = institutionModel.InstitutionDetail.keys.FirstOrDefault(k => k.displayOrder == 2).name;
                cred.value = institutionModel.Value2;
                credentials.Add(cred);

                IEnumerable<InstitutionDetailKey> idk = institutionModel.InstitutionDetail.keys.Where(k => k.displayOrder != 1 && k.displayOrder != 2);
                foreach (InstitutionDetailKey item in idk)
                {
                    cred = new Credential();
                    cred.name = item.name;
                    cred.value = item.val;
                    credentials.Add(cred);
                }

                creds.credential = credentials.ToArray();
                instLogin.AnyIntuitObject = creds;

                Challenges challenges = null;
                ChallengeSession challengeSession = null;
                AccountList accountList = svc.DiscoverAndAddAccounts(institutionModel.InstitutionDetail.institutionId, instLogin, out challenges, out challengeSession);
                discoverAddModel.AccountList = accountList;
                discoverAddModel.Challenges = challenges;
                discoverAddModel.ChallengeSession = challengeSession;
                discoverAddModel.Success = true;
                discoverAddModel.Error = null;
                if (accountList == null && challenges != null)
                {
                    discoverAddModel.MFA = true;
                }
            }
            catch (AggregationCategorizationException ex)
            {
                discoverAddModel.AccountList = null;
                discoverAddModel.Challenges = null;
                discoverAddModel.ChallengeSession = null;
                discoverAddModel.Success = false;
                discoverAddModel.Error = ex.ToString();
            }

            return discoverAddModel;
        }