public UserLogin SaveUserLogin(UserLogin userLogin, long userId)
        {
            if (userLogin == null)
            {
                throw new ArgumentNullException("userLogin", "The given userLogin cannot be null.");
            }
            var userLoginEntity = _userLoginFactory.CreateUserLoginEntity(userLogin, userId);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.SaveEntity(userLoginEntity, true))
                {
                    throw new PersistenceFailureException();
                }
                userLogin.Id = userLoginEntity.UserLoginId;
                return(userLogin);
            }
        }
Exemple #2
0
        public UserEntity CreateUserEntity(UserType userType)
        {
            if (userType == null)
            {
                throw new ArgumentNullException("userType");
            }
            var userEntity = new UserEntity(userType.Id)
            {
                FirstName                        = userType.Name != null ? userType.Name.FirstName : string.Empty,
                LastName                         = userType.Name != null ? userType.Name.LastName : string.Empty,
                MiddleName                       = userType.Name != null ? userType.Name.MiddleName : string.Empty,
                HomeAddressId                    = userType.Address.Id,
                Dob                              = userType.DateOfBirth,
                Email1                           = userType.Email != null?userType.Email.ToString() : string.Empty,
                                          Email2 = userType.AlternateEmail != null?userType.AlternateEmail.ToString() : string.Empty,

                                                       PhoneCell               = userType.MobilePhoneNumber != null ? userType.MobilePhoneNumber.AreaCode + userType.MobilePhoneNumber.Number : string.Empty,
                                                       PhoneHome               = userType.HomePhoneNumber != null ? userType.HomePhoneNumber.AreaCode + userType.HomePhoneNumber.Number : string.Empty,
                                                       PhoneOffice             = userType.OfficePhoneNumber != null ? userType.OfficePhoneNumber.AreaCode + userType.OfficePhoneNumber.Number : string.Empty,
                                                       PhoneOfficeExtension    = userType.PhoneOfficeExtension,
                                                       DefaultRoleId           = (long)userType.DefaultRole,
                                                       CreatedByOrgRoleUserId  = (userType.DataRecorderMetaData != null && userType.DataRecorderMetaData.DataRecorderCreator != null) ? userType.DataRecorderMetaData.DataRecorderCreator.Id == 0 ? (long?)null : userType.DataRecorderMetaData.DataRecorderCreator.Id : (long?)null,
                                                       ModifiedByOrgRoleUserId = (userType.DataRecorderMetaData != null && userType.DataRecorderMetaData.DataRecorderModifier != null) ? userType.DataRecorderMetaData.DataRecorderModifier.Id == 0 ? (long?)null : userType.DataRecorderMetaData.DataRecorderModifier.Id : (long?)null,
                                                       DateCreated             = userType.DataRecorderMetaData != null ? userType.DataRecorderMetaData.DateCreated : DateTime.Now,
                                                       DateModified            = userType.DataRecorderMetaData != null && userType.DataRecorderMetaData.DateModified.HasValue ? userType.DataRecorderMetaData.DateModified.Value : DateTime.Now,
                                                       Ssn       = !string.IsNullOrEmpty(userType.Ssn) ? _cryptographyService.Encrypt(userType.Ssn) : userType.Ssn,
                                                       IsActive  = true,
                                                       UserLogin = _userLoginFactory.CreateUserLoginEntity(userType.UserLogin, userType.Id),
                                                       IsNew     = userType.Id <= 0
            };

            if (userType.Id == 0)
            {
                userEntity.CreatedByOrgRoleUserId = (userType.DataRecorderMetaData != null)
                                                        ? userType.DataRecorderMetaData.DataRecorderCreator.
                                                    OrganizationId
                                                        : (long?)null;
            }



            return(userEntity);
        }