Exemple #1
0
        public bool ForceChangePassword(long userLoginId, string password, bool forceChangePassword, long orgRoleUserId, bool updatePasswordLog)
        {
            var securehash = _userLoginRepository.ForceChangePassword(userLoginId, password, forceChangePassword);

            if (securehash != null && updatePasswordLog)
            {
                _passwordChangelogService.Update(userLoginId, securehash, orgRoleUserId);
            }
            return(securehash != null);
        }
Exemple #2
0
        public SchedulingCustomerEditModel RegisterCustomer(String guid, SchedulingCustomerEditModel customerEditModel)
        {
            if (!string.IsNullOrEmpty(customerEditModel.HomeNumber))// To eliminate masking
            {
                customerEditModel.HomeNumber = customerEditModel.HomeNumber.Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "");
            }

            if (!string.IsNullOrEmpty(customerEditModel.PhoneCell))// To eliminate masking
            {
                customerEditModel.PhoneCell = customerEditModel.PhoneCell.Replace("-", "").Replace("(", "").Replace(")", "").Replace(" ", "");
            }

            var onlineRequestValidationModel = _tempcartService.ValidateOnlineRequest(guid);

            customerEditModel.RequestValidationModel = onlineRequestValidationModel;
            if (onlineRequestValidationModel.RequestStatus != OnlineRequestStatus.Valid)
            {
                return(customerEditModel);
            }

            if (!customerEditModel.DateofBirth.HasValue)
            {
                throw new Exception("Please enter Date of Birth!");
            }

            if (customerEditModel.DateofBirth.Value.GetAge() < _settings.MinimumAgeForScreening)
            {
                throw new Exception(string.Format("Customers below {0} years of age are not allowed for screening.In case of any queries, please call us at {1}", _settings.MinimumAgeForScreening, _settings.PhoneTollFree));
            }

            var customer  = _customerService.SaveCustomer(customerEditModel, onlineRequestValidationModel.TempCart.IsExistingCustomer);
            var userLogin = _userLoginRepository.GetByUserId(customer.Id);

            _passwordChangeLogService.Update(userLogin.Id, new SecureHash(userLogin.Password, userLogin.Salt), customer.CustomerId);
            onlineRequestValidationModel.TempCart.CustomerId      = customer.CustomerId;
            onlineRequestValidationModel.TempCart.MarketingSource = customerEditModel.MarketingSource;

            var tempCart = onlineRequestValidationModel.TempCart;

            _tempcartService.SaveTempCart(tempCart);


            var doesEventCustomerAlreadyExists = tempCart.CustomerId.HasValue ? _eventSchedulerService.DoesEventCustomerAlreadyExists(tempCart.CustomerId.Value, tempCart.EventId.Value) : null;

            if (doesEventCustomerAlreadyExists != null && doesEventCustomerAlreadyExists.FirstValue)
            {
                throw new Exception(doesEventCustomerAlreadyExists.SecondValue);
            }

            customer = tempCart.CustomerId.HasValue ? _customerRepository.GetCustomer(tempCart.CustomerId.Value) : null;
            if (tempCart.ProspectCustomerId.HasValue)
            {
                var prospectCustomer = _prospectCustomerRepository.GetById(tempCart.ProspectCustomerId.Value);
                prospectCustomer.CustomerId                 = customer.CustomerId;
                prospectCustomer.Tag                        = ProspectCustomerTag.OnlineSignup;
                prospectCustomer.IsConverted                = false;
                prospectCustomer.Status                     = (long)ProspectCustomerConversionStatus.NotConverted;
                prospectCustomer.ConvertedOnDate            = DateTime.Now;
                prospectCustomer.Address.StreetAddressLine1 = customer.Address.StreetAddressLine1;
                prospectCustomer.Address.StreetAddressLine2 = customer.Address.StreetAddressLine2;
                prospectCustomer.Address.City               = customer.Address.City;
                prospectCustomer.Address.State              = _stateRepository.GetState(customer.Address.StateId).Name;
                prospectCustomer.Address.ZipCode.Zip        = customer.Address.ZipCode.Zip;
                prospectCustomer.MarketingSource            = customer.MarketingSource;
                prospectCustomer.CallBackPhoneNumber        = customer.HomePhoneNumber;
                prospectCustomer.Email                      = customer.Email;
                prospectCustomer.TagUpdateDate              = DateTime.Now;
                _prospectCustomerRepository.Save(prospectCustomer);
            }
            else
            {
                var prospectCustomer = ((IProspectCustomerRepository)_prospectCustomerRepository).GetProspectCustomerByCustomerId(customer.CustomerId);
                if (prospectCustomer != null)
                {
                    prospectCustomer.CustomerId                 = customer.CustomerId;
                    prospectCustomer.Tag                        = ProspectCustomerTag.OnlineSignup;
                    prospectCustomer.IsConverted                = false;
                    prospectCustomer.Status                     = (long)ProspectCustomerConversionStatus.NotConverted;
                    prospectCustomer.ConvertedOnDate            = DateTime.Now;
                    prospectCustomer.Address.StreetAddressLine1 = customer.Address.StreetAddressLine1;
                    prospectCustomer.Address.StreetAddressLine2 = customer.Address.StreetAddressLine2;
                    prospectCustomer.Address.City               = customer.Address.City;
                    prospectCustomer.Address.State              = _stateRepository.GetState(customer.Address.StateId).Name;
                    prospectCustomer.Address.ZipCode.Zip        = customer.Address.ZipCode.Zip;
                    prospectCustomer.MarketingSource            = customer.MarketingSource;
                    prospectCustomer.CallBackPhoneNumber        = customer.HomePhoneNumber;
                    prospectCustomer.Email                      = customer.Email;
                    prospectCustomer.TagUpdateDate              = DateTime.Now;
                    _prospectCustomerRepository.Save(prospectCustomer);
                }
            }
            return(customerEditModel);
        }
Exemple #3
0
        public UserEditModel Save(UserEditModel userToSave)
        {
            _userModelValidator.ValidateAndThrow(userToSave);

            var userAddress = _addressService.SaveAfterSanitizing(Mapper.Map <AddressEditModel, Address>(userToSave.Address));
            OrganizationRoleUser organizationRoleUser = Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(_sessionContext.UserSession.CurrentOrganizationRole);

            userToSave.DataRecorderMetaData = new DataRecorderMetaData(organizationRoleUser, DateTime.Now, DateTime.Now);

            var        user = Mapper.Map <UserEditModel, User>(userToSave);
            var        isPasswordUpdatedOrCreated = false;
            SecureHash secureHash = null;

            if (userToSave.Id > 0 && string.IsNullOrEmpty(userToSave.Password))
            {
                var existingUser = _userRepository.GetUser(userToSave.Id);
                user.UserLogin.Password               = existingUser.UserLogin.Password;
                user.UserLogin.Salt                   = existingUser.UserLogin.Salt;
                user.UserLogin.UserVerified           = existingUser.UserLogin.UserVerified;//For a scenario: User is created and then immediatly updated
                user.UserLogin.LastPasswordChangeDate = existingUser.UserLogin.LastPasswordChangeDate;
                user.UserLogin.LastLogged             = existingUser.UserLogin.LastLogged;
            }
            else if (!string.IsNullOrEmpty(userToSave.Password))
            {
                secureHash = _oneWayHashingService.CreateHash(userToSave.Password);
                user.UserLogin.Password               = secureHash.HashedText;
                user.UserLogin.Salt                   = secureHash.Salt;
                isPasswordUpdatedOrCreated            = true;
                user.UserLogin.LastPasswordChangeDate = DateTime.Now;
            }

            user.Address = userAddress;
            if (isPasswordUpdatedOrCreated)//&& user.Id > 0 && userToSave.UsersRoles.Count() == 1 && userToSave.UsersRoles.Single().RoleId == (long)Roles.Customer)
            {
                user.UserLogin.UserVerified = false;
            }

            user.UserLogin.IsTwoFactorAuthrequired = userToSave.OverRideTwoFactorAuthrequired ? userToSave.IsTwoFactorAuthrequired : (bool?)null;


            user = _userRepository.SaveUser(user);
            if (isPasswordUpdatedOrCreated && secureHash != null && !(user.Id > 0 && userToSave.UsersRoles.Count() == 1 && userToSave.UsersRoles.Single().RoleId == (long)Roles.Customer))
            {
                _passwordChangelogService.Update(user.Id, secureHash, _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId);
            }

            userToSave.Id = user.Id;
            //map & save user roles
            _orgRoleUserRepository.DeactivateAllOrganizationRolesForUser(user.Id);
            foreach (var organizationRoleModel in userToSave.UsersRoles)
            {
                organizationRoleModel.UserId = user.Id;
                var orgRoleUser = _orgRoleUserRepository.SaveOrganizationRoleUser(Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(organizationRoleModel));
                var roleId      = GetParentRoleIdByRoleId(orgRoleUser.RoleId);
                switch (roleId)
                {
                case (long)Roles.Technician:
                    var technician = Mapper.Map <TechnicianModel, Technician>(userToSave.TechnicianProfile);
                    technician.TechnicianId = orgRoleUser.Id;
                    var repository = ((IRepository <Technician>)_technicianRepository);
                    repository.Save(technician);
                    if (!string.IsNullOrWhiteSpace(userToSave.TechnicianProfile.Pin))
                    {
                        _pinChangeLogService.Update(userToSave.TechnicianProfile.Pin.Encrypt(), orgRoleUser.Id, organizationRoleUser.Id);
                    }
                    break;

                case (long)Roles.MedicalVendorUser:
                    var physician = Mapper.Map <PhysicianModel, Physician>(userToSave.PhysicianProfile);
                    physician.PhysicianId             = orgRoleUser.Id;
                    physician.AuthorizedStateLicenses =
                        _physicianLicenseModelFactory.CreateMultiple(userToSave.PhysicianProfile.Licenses,
                                                                     orgRoleUser.Id);
                    _physicianRepository.SavePhysician(physician);
                    break;

                case (long)Roles.CorporateAccountCoordinator:
                    var accountCoordinator = Mapper.Map <AccountCoordinatorProfileModel, AccountCoordinatorProfile>(userToSave.AccountCoordinatorProfile);
                    accountCoordinator.AccountCoordinatorId = orgRoleUser.Id;
                    var accountCoordinatorRepository = ((IRepository <AccountCoordinatorProfile>)_accountCoordinatorProfileRepository);
                    accountCoordinatorRepository.Save(accountCoordinator);
                    break;

                case (long)Roles.CallCenterRep:
                    var callCenterRepProfile = new CallCenterRepProfile
                    {
                        CallCenterRepId = orgRoleUser.Id,
                        CanRefund       = false,
                        CanChangeNotes  = false,
                        DialerUrl       = organizationRoleModel.DialerUrl
                    };
                    _callCenterRepProfileRepository.Save(callCenterRepProfile);
                    break;
                }
            }

            if (userToSave.UsersRoles.Any(x => x.RoleId == (long)Roles.NursePractitioner))
            {
                var userNpiInfo = new UserNpiInfo
                {
                    UserId     = userToSave.Id,
                    Npi        = !string.IsNullOrEmpty(userToSave.Npi) ? userToSave.Npi : null,
                    Credential = !string.IsNullOrEmpty(userToSave.Credential) ? userToSave.Credential : null
                };
                _userNpiInfoRepository.Save(userNpiInfo);
            }

            var systemUserInfo = new SystemUserInfo
            {
                EmployeeId = userToSave.UsersRoles.Count() == 1 && userToSave.UsersRoles.Any(x => x.RoleId == (long)Roles.Customer) ? string.Empty : userToSave.EmployeeId,
                UserId     = userToSave.Id
            };

            _systemUserInfoRepository.Save(systemUserInfo);

            return(userToSave); //this does not return the same object. the saved user are out of sync at this point.!!
        }