public HttpResponseMessage GetNewToken(string UserId)
        {
            // - Validate incoming payload model
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <TokenSMS> response = new ItemResponse <TokenSMS>();

            response.Item = TokenSMSService.UserGetByNewToken(UserId);

            //Service to grab user Phone#
            UserProfile UserInfo  = _UserProfileService.GetUserById(UserId);
            String      UserPhone = UserInfo.Phone;

            //Service to Send New Text with existing Model
            NotifySMSRequest RequestText = new NotifySMSRequest();

            RequestText.Phone    = UserPhone;
            RequestText.TokenSMS = response.Item.TokenHash;
            object NewTextResult = NotifySMSService.SendConfirmText(RequestText);

            return(Request.CreateResponse(NewTextResult));
        }
Example #2
0
        public HttpResponseMessage ForgotPassword(InsertTokenRequest model)
        {
            if (!ModelState.IsValid)
            {
                Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            bool success = false;

            ApplicationUser thisUser = UserService.GetUser(model.Email);

            UserDomain smsText = new UserDomain();

            smsText = _UserProfileService.GetPhoneNumberByEmail(model.Email);

            if (thisUser != null)
            {
                //- Create Token

                model.TokenType = Enums.TokenType.ForgotPassword;

                model.UserId = thisUser.Id;

                Guid token = _TokenService.RegisterToken(model);

                //- Create the link
                string link = "/public/resetpassword/" + token.ToString();

                link = HttpContext.Current.Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped) + link;

                //- Send Link to user email
                EmailRequest confirm = new EmailRequest();

                confirm.UserEmail = thisUser.Email;
                confirm.Subject   = "Reset Your Password";
                confirm.Content   = link;

                _UserEmailService.SendEmail(confirm);

                // TEXTING SERVICE BUILT BY RAVID YOEUN
                NotifySMSRequest userModel = new NotifySMSRequest();

                userModel.Phone     = smsText.PhoneNumber;
                userModel.firstName = smsText.FirstName;
                userModel.lastName  = smsText.LastName;
                userModel.url_link  = link;

                NotifySMSService.SendConfirmText(userModel);
                success = true;
            }

            ItemResponse <bool> response = new ItemResponse <bool>();

            response.Item = success;

            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public HttpResponseMessage sendText(NotifySMSRequest model)
        {
            ItemResponse <object> response = new ItemResponse <object>();

            try
            {
                response.Item = NotifySMSService.SendConfirmText(model);
            }
            catch (ArgumentException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, response));
        }
        public void NotifyAllCompanyUsers(NotificationInsertRequest model, List <CompanyEmployeeDomain> NotificationList)
        {
            //Instantialize a new NotifySmsRequest
            NotifySMSRequest       companyUser = new NotifySMSRequest();
            EmployeeProfileRequest Employee    = new EmployeeProfileRequest();

            Employee.companyId = model.CompanyId;

            //List<CompanyEmployeeDomain> notificationList = _UserProfileService.GetEmployeesByCompanyId(Employee.companyId);


            foreach (CompanyEmployeeDomain employee in NotificationList)
            {
                model.UserId    = employee.UserId;
                model.CompanyId = employee.CompanyId;



                companyUser.Phone = employee.PhoneNumber;

                //Send out text message
                try
                {
                    NotifySMSService.SendBidNotification(companyUser);
                }

                catch (ArgumentException)
                {
                    companyUser.Phone = "";
                }

                catch (Exception)
                {
                }

                SignalRHub.SendNotification(model);
            }
        }
        //Service ran for creating a new user - pass in users id and request model
        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
            DataProvider.ExecuteNonQuery(GetConnection, "UserProfiles_Insert" // stored procedure
                                         , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {                                                                 //input fields
                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, we want to give them (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();
                    UserCreditsRequest insertFriendCredits   = new UserCreditsRequest();

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

                else
                {
                    //send error message that token has already been used.
                }
            }

            //Activity Services
            ActivityLogRequest Activity = new ActivityLogRequest();

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

            //----------//create a new Website Id ---------updated the AddUserToWebsite using the updated domain with int[]
            //getting the websiteId via the website Slug
            Website w    = null;
            string  Slug = model.Slug;

            w = WebsiteService.GetWebsiteIdBySlug(Slug);

            int[] WebsiteIds = new int[1];
            WebsiteIds[0] = w.Id;
            //populating userwebsite object
            UserWebsite userWebsite = new UserWebsite();

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

            //creae a new Customer role
            //set role as customer by default - change role by admin panel
            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
            //braintree used for handling credit card transactions
            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)
            {
                //if phone number is already registered will not send a registration check
                //should never get this far
                throw new System.ArgumentException(ex.Message);
            }

            //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);
        }
        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);
        }