Exemplo n.º 1
0
        public BpiSubscriber AddSubscriber(
            string firstName, 
            string lastName, 
            string userName, 
            string password, 
            string companyName, 
            int companyTypeId, 
            string terms,             
            string cardholderName, 
            string cardholderZip, 
            string cardNumber, 
            string cvv, 
            string expiryMonth, 
            string expiryYear)
        {
            ////  STEP 1: ADD TO SUBSCRIBER TABLE
            ////  MAKE INACTIVE SO THEY CANT LOGIN
            ////  THEY NEED TO BE APPROVED FIRST
            ////  SET SUBSCRIBERTYPEID = 1 [BpiSubscriber]
            IGenericBlipShip<Subscriber> subscriberRepo = GetGenericBlipShipRepository<Subscriber>();
            Subscriber newSubscriber = new Subscriber()
            {
                AddedOn = DateTime.Now,
                FirstName = firstName,
                FullName = firstName + " " + lastName,
                IsActive = false,
                LastName = lastName,
                LastUpdatedOn = DateTime.Now,
                Password = password,
                SubscriberTypeId = 1,
                UserName = userName,
                GatewayCustomerId = ""
            };

            subscriberRepo.Add(newSubscriber);

            ////  STEP 3: ADD THE COMPANY
            ////  ALL ITEMS SHOULD BE PASSED IN
            IGenericBlipShip<SubscriberCompany> compRepo = GetGenericBlipShipRepository<SubscriberCompany>();
            SubscriberCompany newCompany = new SubscriberCompany()
            {
                CompanyName = companyName,
                CompanyTypeId = companyTypeId,
                SubscriberId = newSubscriber.SubscriberId
            };

            compRepo.Add(newCompany);

            ////    STEP 4: ADD THE SUBSCRIPTION
            var newSubscription = AddSubscription(newSubscriber.SubscriberId, companyTypeId, terms, companyTypeId == 1 ? companyName : "");

            BpiSubscriptionType subscriptionType = new BpiSubscriptionType();

            switch (companyTypeId) {
                case 1:
                    subscriptionType = GetSubscriptionByInstitution(companyName).Where(x => x.IsYearly == (terms.Contains(Constants.TERMS_ANNUAL) ? true : false)).FirstOrDefault();
                    break;
                case 3:
                    subscriptionType = GetSubsciptionForConsultant().Where(x => x.IsYearly == (terms.Contains(Constants.TERMS_ANNUAL) ? true : false)).FirstOrDefault();
                    break;
            }

            ////    STEP 5: ADD THE ORDER TO THE GATEWAY
            ////    THE RETURNS THE GATEWAY USER ID WHICH NEEDS TO BE SAVED TO SUBSCRIBER TABLE
            var order = new BpiOrder
            {
                Amount = (decimal)subscriptionType.ChargeAmount,
                CardHolderFirstName = cardholderName,
                CreditCardNumber = cardNumber,
                Cvv = cvv,
                ExpirationMonth = expiryMonth,
                ExpirationYear = expiryYear,
                PlanName = subscriptionType.SubscriptionTypeName,
                CardholderPostalCode = cardholderZip
            };

            new PaymentGateway().CreateTransaction(order);

            newSubscriber.GatewayCustomerId = order.GatewayCustomerId;
            subscriberRepo.Attach(newSubscriber);

            return Mapper.DynamicMap<BpiSubscriber>(newSubscriber);

            #region commented code

            ////  STEP 2: ADD THE ADDRESS
            ////  FILL IN THE COUNTRY TYPE INFO
            ////  FILL IN THE ADDRESS TYPE INFO
            ////  SET ADDRESSTYPEID = 1 [Billing]
            ////IRepository<SubscriberAddress> addressRepo = GetGenericBlipShipRepository<SubscriberAddress>();
            ////SubscriberAddress newAddress = new SubscriberAddress() {
            ////    AddedOn = DateTime.Now,
            ////    AddressLine1 = subscriber.Address.AddressLine1,
            ////    AddressLine2 = subscriber.Address.AddressLine2 ?? string.Empty,
            ////    AddressTypeId = 1,
            ////    City = subscriber.Address.City,
            ////    CountryTypeId = subscriber.Address.CountryId,
            ////    IsActive = true,
            ////    LastUpdatedOn = DateTime.Now,
            ////    StateProvince = subscriber.Address.StateProvince,
            ////    ZipPostal = subscriber.Address.ZipPostal,
            ////    SubscriberId = newSubscriber.SubscriberId
            ////};

            ////addressRepo.Add(newAddress);

            ////newSubscriber.SubscriberAddresses.Add(newAddress);

            //newSubscriber.SubscriberCompanies.Add(newCompany);

            ////  STEP 4: ADD THE JOB TYPE
            ////  ALL ITEMS SHOULD BE PASSED IN
            //IRepository<SubscriberJobFunction> jobRepo = GetGenericBlipShipRepository<SubscriberJobFunction>();
            //SubscriberJobFunction newJob = new SubscriberJobFunction() {
            //    JobFunctionTypeId = subscriber.JobType,
            //    SubscriberId = newSubscriber.SubscriberId
            //};

            //jobRepo.Add(newJob);

            //newSubscriber.SubscriberJobFunctions.Add(newJob);

            ////  STEP 5: ADD THE PHONENUMBER
            ////  SET PHONETYPEID = 1 [Work - Cell]
            //IRepository<SubscriberPhone> phoneRepo = GetGenericBlipShipRepository<SubscriberPhone>();
            //SubscriberPhone newPhone = new SubscriberPhone() {
            //    PhoneNumber = subscriber.PhoneNumber,
            //    PhoneTypeId = 1,
            //    SubscriberId = newSubscriber.SubscriberId
            //};

            //phoneRepo.Add(newPhone);

            //newSubscriber.SubscriberPhones.Add(newPhone);

            ////  STEP 6: ADD THE SUBSCRIPTION
            ////  GET THE CONFIG FOR A FREETRIAL [SubscriptionType = 5]
            ////  ADD THE SUBSCRIPTION BUT DONT ACTIVATE IT
            //IGenericBlipShip<Subscription> subscRepo = GetGenericBlipShipRepository<Subscription>();
            //Subscription newSubscription = new Subscription()
            //{
            //    AddedOn = DateTime.Now,
            //    ApiKey = Guid.NewGuid(),
            //    FriendlyName = newSubscriber.FullName,
            //    IsActive = false,
            //    LastUpdatedOn = DateTime.Now,
            //    SubscriberId = newSubscriber.SubscriberId,
            //    SubscriptionTypeId = 5,
            //    GatewaySubscriptionId = subscriber.SubscriptionModel.GatewaySubscriptionId
            //};

            //subscRepo.Add(newSubscription);

            ////  STEP 7: ADD THE FEATURES
            ////  GET ALL THE FEATURES FROM THE CONFIG FOR THE SPECIFIC SUBSCRIPTION
            ////  USE FREETRIAL CONFIG [SubscriptionType = 5]
            //IRepository<SubscriptionTypeConfig> configRepo = GetGenericBlipShipRepository<SubscriptionTypeConfig>();
            //List<int> featureIds = configRepo.Find(x => x.IsActive && x.SubscriptionTypeId == 5).Select(x => x.FeatureTypeId).ToList();

            //IRepository<SubscriptionFeature> subFeatRepo = GetGenericBlipShipRepository<SubscriptionFeature>();

            //foreach (var featureId in featureIds) {
            //    subFeatRepo.Add(new SubscriptionFeature() {
            //        AddedOn = DateTime.Now,
            //        FeatureTypeId = featureId,
            //        IsActive = true,
            //        LastUpdateOn = DateTime.Now,
            //        SubscriptionId = newSubscription.SubscriptionId
            //    });
            //}

            ////  [TODO] RETURN THE FULLY POPULATED BPISUBSCRIBER
            ////  UNNECESSARY RIGHT NOW BECAUSE THEY MUST BE APPROVED BY ADMIN
            //BpiSubscriber returnSubscriber = new BpiSubscriber();
            #endregion
        }
Exemplo n.º 2
0
        public BpiSubscription AddSubscription(int subscriberId,int companyTypeId, string terms,string fdicCert = "")
        {
            var repo = GetGenericBlipShipRepository<Subscription>();

            BpiSubscriptionType subType = new BpiSubscriptionType();
            switch (companyTypeId) {
                case 1:
                    var subs = GetSubscriptionByInstitution(fdicCert);
                    var isYearly = terms == Constants.TERMS_ANNUAL ? true : false;
                    subType = subs.Where(x => x.IsYearly == isYearly).FirstOrDefault();
                    break;
                case 3:
                    var cons = GetSubsciptionForConsultant();
                    var yearly = terms == Constants.TERMS_ANNUAL ? true : false;
                    subType = cons.Where(x => x.IsYearly == yearly).FirstOrDefault();
                    break;
            }

            var newSubscription = new Subscription {
                AddedOn = DateTime.Now,
                ApiKey = Guid.NewGuid(),
                FriendlyName = subType.FriendlyName,
                GatewaySubscriptionId = "",
                IsActive = false,
                LastUpdatedOn = DateTime.Now,
                SubscriberId = subscriberId,
                SubscriptionTypeId = subType.SubscriptionTypeId
            };
            repo.Add(newSubscription);

            return Mapper.DynamicMap<BpiSubscription>(newSubscription);
        }