public ActionResult Login(SessionViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = SubscriberModel.ValidateSubscriber(model.LoginViewModel.UserName, model.LoginViewModel.Password);
                if (user != null)
                {

                    SessionViewModel sessionModel = new SessionViewModel();
                    sessionModel.CurrentFilters = new Dictionary<string, string>();

                    //  TODO: MAKE SURE THERE IS SOMETHING HERE WHEN GOING TO A CONSULTANT
                    string currentInstitution = "";
                    if(user.CompanyType == 1){
                        currentInstitution = SubscriberModel.GetUserCompany(user.SubscriberId).CompanyName;
                    }

                    sessionModel.CurrentFilters.Add(Constants.CURRENT_INSTITUTION_FDIC, currentInstitution);
                    sessionModel.SubscriberViewModel = user;

                    Session[Constants.SESSION_NAME] = sessionModel;

                    #region FA cookie
                    var serializeModel = new BlipShipPrincipalSerializeModel
                    {
                        UserId = 1,
                        UserName = model.LoginViewModel.UserName,
                    };

                    string userData = JsonConvert.SerializeObject(serializeModel);
                    var ticket = new FormsAuthenticationTicket(
                        1,
                        "bpicookie",
                        DateTime.Now,
                        DateTime.Now.AddMinutes(120),
                        false,
                        userData,
                        FormsAuthentication.FormsCookiePath
                        );

                    string encryptedTicket = FormsAuthentication.Encrypt(ticket);
                    var formsCookie = new HttpCookie("bpicookie", encryptedTicket);

                    Response.Cookies.Add(formsCookie);
                    #endregion

                    return RedirectToAction("Index", "Dashboard");
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
        public ActionResult Index(SessionViewModel model)
        {
            if (Session[Constants.SESSION_NAME] == null)
            {
                Session[Constants.SESSION_NAME] = new SessionViewModel();
            }

            var sessionModel = Session[Constants.SESSION_NAME] as SessionViewModel;

            //  MAKES SURE IF BANK IS SELECTED THERE IS AN FDIC NUMBER
            if (model.SubscriberViewModel.CompanyType == 1 && string.IsNullOrEmpty(model.SubscriberViewModel.FdicCertNumber))
            {
                ModelState.AddModelError("RegisterViewModel.FdicCertNumber", "The FDIC Certificate Number field is required.");
            }

            //  MAKES SURE THE FDIC NUMBER IS VALID
            if (model.SubscriberViewModel.CompanyType == 1 && !SubscriberModel.IsValidFdicNumber(model.SubscriberViewModel.FdicCertNumber))
            {
                ModelState.AddModelError("RegisterViewModel.FdicCertNumber", "The FDIC Certificate Number is not associated with an institution.");
            }

            //  MAKES SURE IF OTHER IS SELECTED THERE IS A COMPANY NAME
            if (model.SubscriberViewModel.CompanyType == 3 && string.IsNullOrEmpty(model.SubscriberViewModel.CompanyName))
            {
                ModelState.AddModelError("RegisterViewModel.FdicCertNumber", "The Company Name field is required.");
            }

            if (ModelState.IsValid) {
                //  USING THE SUBSCRIBER VIEW MODEL WE CREATE SUBSCRIPTION INFO

                model.SubscriberViewModel.SubscriptionTerms = Request["subscriptionTerms"].ToString();

                var subscriber = new SubscriberModel().AddSubscriber(
                    model.SubscriberViewModel.FdicCertNumber,
                    model.SubscriberViewModel.FirstName,
                    model.SubscriberViewModel.LastName,
                    model.SubscriberViewModel.CompanyType,
                    model.SubscriberViewModel.UserName,
                    model.SubscriberViewModel.Password,
                    model.SubscriberViewModel.CompanyName,
                    model.SubscriberViewModel.CardHolderName,
                    model.SubscriberViewModel.CardHolderZip,
                    model.SubscriberViewModel.CreditCardNumber,
                    model.SubscriberViewModel.Cvv,
                    model.SubscriberViewModel.ExpirationMonth,
                    model.SubscriberViewModel.ExpirationYear,
                    model.SubscriberViewModel.SubscriptionTerms);

                sessionModel.SubscriberViewModel = subscriber;

                sessionModel.CurrentFilters = new Dictionary<string, string>();
                //  TODO: GET THE FDIC NUMBER OR LAST SELECTED
                sessionModel.CurrentFilters.Add(Constants.CURRENT_INSTITUTION_FDIC, subscriber.CompanyName);

                #region FA cookie
                var serializeModel = new BlipShipPrincipalSerializeModel
                {
                    UserId = 1,
                    UserName = model.LoginViewModel.UserName,
                };

                string userData = JsonConvert.SerializeObject(serializeModel);
                var ticket = new FormsAuthenticationTicket(
                    1,
                    FormsAuthentication.FormsCookieName,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(120),
                    false,
                    userData,
                    FormsAuthentication.FormsCookiePath
                    );

                string encryptedTicket = FormsAuthentication.Encrypt(ticket);
                var formsCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                Response.Cookies.Add(formsCookie);
                #endregion

                Session[Constants.SESSION_NAME] = sessionModel;
                return RedirectToAction("Index", "Dashboard");
            }

            sessionModel.SubscriberViewModel = model.SubscriberViewModel;
            sessionModel.SubscriberViewModel.SubscriptionList = SubscriberModel.GetSubscriptionList();
            Session[Constants.SESSION_NAME] = sessionModel;
            return View(sessionModel);
        }