예제 #1
0
        public void CreateUserProfile(string userId, CreateUserRequest model)
        {
            //Updated the create user so that it can take in the tokenHash param if there is one provided --Anna

            DataProvider.ExecuteNonQuery(GetConnection, "UserProfiles_Insert"
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@UserId", userId);
                paramCollection.AddWithValue("@FirstName", model.FirstName);
                paramCollection.AddWithValue("@LastName", model.LastName);
                paramCollection.AddWithValue("@TokenHash", model.TokenHash);     //this is provided if they were referred by a current customer
            }
                                         );

            //referral coupon
            //if TokenHash referral is null, they're making a new account.
            //if TokenHash referral is NOT null, give new user a Coupon value and add it to their Credit.
            // we also want to give the original user (one who referred) the same Coupon value and add it to their Credit.
            if (model.TokenHash != null)
            {
                //retrieve coupon information + token information based on the token hash.
                CouponsDomain userCoupon = TokenService.GetReferralTokenByGuid(model.TokenHash);
                if (userCoupon.Token.Used == null)
                {
                    //send token to Credit service
                    UserCreditsRequest insertRefferalCredits = new UserCreditsRequest();

                    //send credits to new User who was referred
                    insertRefferalCredits.Amount          = userCoupon.CouponValue;
                    insertRefferalCredits.TransactionType = "Add";
                    insertRefferalCredits.UserId          = userId;
                    _CreditsService.InsertUserCredits(insertRefferalCredits);

                    //send credits to Friend who referred new user BUT ONLY AFTER THE REFERRED FRIEND HAS COMPLETED THEIR FIRST ORDER----
                    //see BrainTreeService, Line 130
                }
            }

            //Activity Services - update the activity log
            ActivityLogRequest Activity = new ActivityLogRequest();

            Activity.ActivityType = ActivityTypeId.NewAccount;
            _ActivityLogService.InsertActivityToLog(userId, Activity);

            //Associating a User to website(s)
            Website w    = null;
            string  Slug = model.Slug;

            w = WebsiteService.GetWebsiteIdBySlug(Slug);

            int[] WebsiteIds = new int[1];
            WebsiteIds[0] = w.Id;

            UserWebsite userWebsite = new UserWebsite();

            userWebsite.UserId     = userId;
            userWebsite.WebsiteIds = WebsiteIds;
            WebsiteService.AddUserToWebsite(userWebsite);

            //creae a new Customer role
            UserProfile aspUser = new UserProfile();

            aspUser.FirstName = model.FirstName;
            aspUser.LastName  = model.LastName;
            aspUser.RoleId    = ConfigService.CustomerRole;

            _AdminService.CreateUserRole(userId, aspUser);

            //create a new Braintree account using UserID
            CustomerPaymentRequest Payment = new CustomerPaymentRequest();

            Payment.FirstName = model.FirstName;
            Payment.LastName  = model.LastName;
            Payment.UserId    = userId;
            Payment.Phone     = model.Phone;

            //Send a confirmation Text Msg
            string UserSMSToken = TokenSMSService.TokenSMSInsert(userId);
            //send a text msg
            NotifySMSRequest NotifyCustomer = new NotifySMSRequest();

            NotifyCustomer.Phone    = model.Phone;
            NotifyCustomer.TokenSMS = UserSMSToken;

            try
            {
                NotifySMSService.SendConfirmText(NotifyCustomer);
            }
            catch (ArgumentException /*ex*/)
            {
                DeleteUserProfileByUserId(userId);
                DeleteUserWebsiteByUserId(userId);
                DeleteAspNetUserByUserId(userId);

                throw new System.ArgumentException(ex.Message);
            }

            //send a confirmation email
            _EmailService.SendProfileEmail(userTokenGuid, model.Email);

            //bringg create account
            RegisterBringgRequest bringgRequest = new RegisterBringgRequest();

            bringgRequest.Name   = model.FirstName + " " + model.LastName;
            bringgRequest.Phone  = model.Phone;
            bringgRequest.Email  = model.Email;
            bringgRequest.UserId = userId;
            this._CreateCustomerTask.Execute(bringgRequest);



            _CreateCustomerTask.Execute(bringgRequest);

            BrainTreeService brainTree = new BrainTreeService();

            brainTree.newCustomerInsert(Payment);

            ////generate a new token
            Guid userTokenGuid = TokenService.tokenInsert(userId);

            //send a confirmation email

            _EmailService.SendProfileEmail(userTokenGuid, model.Email, model.Slug);
        }