public SessionViewModel()
 {
     _subscriberModel = new SubscriberModel();
     _loginModel = new LoginModel();
     _dashboardModel = new DashboardModel();
     _currentFilters = new Dictionary<string, string>();
     _contactUsModel = new ContactUs();
     _supportModel = new Support();
 }
        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);
        }
        public SubscriberModel AddSubscriber(
            string certificate, 
            string firstName, 
            string lastName, 
            int companyType, 
            string userName, 
            string password, 
            string companyName, 
            string cardholderName, 
            string cardholderZip, 
            string cardNumber, 
            string cvv, 
            string expiryMonth, 
            string expiryYear,
            string terms)
        {
            switch (companyType) {
                case 1:
                    //  FOR BANKS WE SET THE COMPANY NAME TO THE CERT NUMBER FOR LOOKUP
                    companyName = certificate;
                    break;
                case 3:
                    //  FOR CONSULTANTS WE LEAVE THE COMPANY AS IS AND THE CERTIFICATE PARAM IS EMPTY
                    break;
            }

            //  ADD THE SUBSCRIBER TO THE BLIPSHIP DATABASE
            var subscriber = BlipShipServices.SubscriberService.AddSubscriber(
                firstName,
                lastName,
                userName,
                password,
                companyName,
                companyType,
                terms,
                cardholderName,
                cardholderZip,
                cardNumber,
                cvv,
                expiryMonth,
                expiryYear);

            var subModel = new SubscriberModel {
                AddedOn = subscriber.AddedOn,
                CompanyName = companyName,
                CompanyType = companyType,
                FirstName = subscriber.FirstName,
                FullName = subscriber.FullName,
                GatewayCustomerId = subscriber.GatewayCustomerId,
                IsActive = subscriber.IsActive,
                LastName = subscriber.LastName,
                SubscriberId = subscriber.SubscriberId,
                UserName = subscriber.UserName
            };

            return subModel;
        }
        public static SubscriberModel ValidateSubscriber(string userName, string password)
        {
            var bpiSubscriber = BlipShipServices.SubscriberService.ValidateSubscriber(userName, password);

            if (bpiSubscriber == null) {
                return null;
            }

            var subscriber = new SubscriberModel {
                AddedOn = bpiSubscriber.AddedOn,
                CompanyName = bpiSubscriber.Company.CompanyName,
                CompanyType = bpiSubscriber.Company.CompanyTypeId,
                FdicCertNumber = bpiSubscriber.Company.FdicCertificate,
                FirstName = bpiSubscriber.FirstName,
                FullName = bpiSubscriber.FullName,
                GatewayCustomerId = bpiSubscriber.GatewayCustomerId,
                IsActive= bpiSubscriber.IsActive,
                LastName = bpiSubscriber.LastName,
                LastUpdatedOn = bpiSubscriber.LastUpdatedOn,
                SubscriberId = bpiSubscriber.SubscriberId,
                SubscriberTypeId = bpiSubscriber.SubscriberTypeId,
                UserName = bpiSubscriber.UserName
            };

            return subscriber;
        }