Esempio n. 1
0
 protected void ExpectSaveEntity(bool saveSuccessful, bool expectWithRefetchAfterSaveParameter)
 {
     if (expectWithRefetchAfterSaveParameter)
     {
         Expect.Call(_dataAccessAdapter.SaveEntity(null, true)).IgnoreArguments().Return(saveSuccessful);
     }
     else
     {
         Expect.Call(_dataAccessAdapter.SaveEntity(null)).IgnoreArguments().Return(saveSuccessful);
     }
 }
        public bool Save(SafeComputerHistory safeComputerHistory)
        {
            var safeComputerHistoryEntity = Mapper.Map <SafeComputerHistory, SafeComputerHistoryEntity>(safeComputerHistory);

            using (IDataAccessAdapter adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(adapter);
                var list         = (from c in linqMetaData.SafeComputerHistory where c.UserLoginId == safeComputerHistory.UserLoginId && !c.IsActive select c);
                if (list.Count() != 0)
                {
                    foreach (var computerHistoryEntity in list)
                    {
                        if (computerHistoryEntity.BrowserType == safeComputerHistory.BrowserType &&
                            computerHistoryEntity.ComputerIp == safeComputerHistory.ComputerIp)
                        {
                            safeComputerHistoryEntity              = computerHistoryEntity;
                            safeComputerHistoryEntity.IsNew        = false;
                            safeComputerHistoryEntity.DateModified = DateTime.Now;
                            break;
                        }
                    }
                }
                else
                {
                    safeComputerHistoryEntity.IsNew = true;
                }

                if (!adapter.SaveEntity(safeComputerHistoryEntity, false))
                {
                    throw new PersistenceFailureException();
                }
                return(true);
            }
        }
Esempio n. 3
0
        public SecureHash ResetPassword(long userLoginId, string password, bool userVerified = true)
        {
            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var userLoginEntity = new UserLoginEntity(userLoginId);

                if (myAdapter.FetchEntity(userLoginEntity))
                {
                    userLoginEntity.IsNew = false;
                    var securehash = _oneWayHashingService.CreateHash(password);
                    userLoginEntity.Password = securehash.HashedText;
                    userLoginEntity.Salt     = securehash.Salt;

                    userLoginEntity.UserVerified           = userVerified;
                    userLoginEntity.LastPasswordChangeDate = DateTime.Now;
                    if (userVerified)
                    {
                        userLoginEntity.ResetPwdQueryString = null;
                    }
                    myAdapter.SaveEntity(userLoginEntity, true);
                    return(securehash);
                }
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Saves any changes to the specified data to the DB.
        /// </summary>
        /// <param name="dataToSave">The data to save, must be a CommonEntityBase or a list of CommonEntityBase's.</param>
        /// <param name="dataAccessAdapter">The data access adapter.</param>
        /// <returns>The number of persisted entities.</returns>
        public static int Save(object dataToSave, IDataAccessAdapter dataAccessAdapter)
        {
            var listItemType = ListBindingHelper.GetListItemType(dataToSave);

            if (typeof(IEntity2).IsAssignableFrom(listItemType))
            {
                var enumerable = dataToSave as IEnumerable;
                return(enumerable == null?Convert.ToInt32(dataAccessAdapter.SaveEntity((IEntity2)dataToSave)) : SaveEntities(enumerable, dataAccessAdapter));
            }
            return(0);
        }
Esempio n. 5
0
        public bool Save(PinChangelog pinChangelog)
        {
            var PinChangelogEntity = Mapper.Map <PinChangelog, PinChangelogEntity>(pinChangelog);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.SaveEntity(PinChangelogEntity, false))
                {
                    throw new PersistenceFailureException();
                }
                return(true);
            }
        }
Esempio n. 6
0
        public bool Save(LoginOtp loginOtp)
        {
            var loginOtpEntity = Mapper.Map <LoginOtp, LoginOtpEntity>(loginOtp);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                loginOtpEntity.IsNew = !myAdapter.FetchEntity(new LoginOtpEntity(loginOtp.UserLoginId));;
                if (!myAdapter.SaveEntity(loginOtpEntity, false))
                {
                    throw new PersistenceFailureException();
                }
                return(true);
            }
        }
Esempio n. 7
0
        public bool Save(LoginSettings loginSettings)
        {
            var loginSettingsEntity = Mapper.Map <LoginSettings, LoginSettingsEntity>(loginSettings);

            using (IDataAccessAdapter adapter = PersistenceLayer.GetDataAccessAdapter())
            {
                loginSettingsEntity.IsNew = !adapter.FetchEntity(new LoginSettingsEntity(loginSettings.UserLoginId));

                if (!adapter.SaveEntity(loginSettingsEntity, false))
                {
                    throw new PersistenceFailureException();
                }
                return(true);
            }
        }
Esempio n. 8
0
        public HostFacilityViability Save(HostFacilityViability domainObject)
        {
            var hostFacilityRankingEntity = _hostFacilityRankingMapper.Map(domainObject);

            SetIsCurrentForRoleFlagoffForRole(domainObject.CreatedBy.RoleId, domainObject.HostId);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.SaveEntity(hostFacilityRankingEntity, true))
                {
                    throw new PersistenceFailureException();
                }

                return(_hostFacilityRankingMapper.Map(hostFacilityRankingEntity));
            }
        }
Esempio n. 9
0
        public HostDeposit Save(HostDeposit hostDeposit)
        {
            NullArgumentChecker.CheckIfNull(hostDeposit, "hostDeposit");

            var hostPaymentEntity = _hostDepositFactory.CreateHostPayment(hostDeposit);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.SaveEntity(hostPaymentEntity, true))
                {
                    throw new PersistenceFailureException();
                }
                var address = _addressRepository.GetAddress(hostPaymentEntity.MailingAddressId.Value);
                return(_hostDepositFactory.CreateHostDeposit(hostPaymentEntity, address));
            }
        }
Esempio n. 10
0
        public bool UpdateFraminghamValue(long customerEventScreeningTestId, decimal framinghamValue)
        {
            var testReadingId = GetListOfTestReadingAndReadingId((int)TestType.FraminghamRisk).Find(testReadingReadingPair =>
                                                                                                    (testReadingReadingPair.
                                                                                                     FirstValue ==
                                                                                                     (int)
                                                                                                     ReadingLabels.
                                                                                                     FraminghamRisk)).
                                SecondValue;
            var customerEventReadingEntity = new CustomerEventReadingEntity
            {
                Value         = framinghamValue.ToString(),
                TestReadingId = testReadingId,
                CustomerEventScreeningTestId =
                    customerEventScreeningTestId
            };

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(myAdapter);

                var framinghamCustomerReading = linqMetaData.CustomerEventReading.Where(customerEventReading => customerEventReading.CustomerEventScreeningTestId == customerEventScreeningTestId &&
                                                                                        customerEventReading.TestReadingId == testReadingId).SingleOrDefault();

                if (framinghamCustomerReading != null && framinghamCustomerReading.CustomerEventReadingId > 0)
                {
                    IRelationPredicateBucket bucket = new RelationPredicateBucket(CustomerEventReadingFields.TestReadingId == testReadingId);
                    bucket.PredicateExpression.AddWithAnd(CustomerEventReadingFields.CustomerEventScreeningTestId ==
                                                          customerEventScreeningTestId);

                    if (myAdapter.UpdateEntitiesDirectly(customerEventReadingEntity, bucket) == 0)
                    {
                        throw new PersistenceFailureException();
                    }
                }
                else
                {
                    if (!myAdapter.SaveEntity(customerEventReadingEntity))
                    {
                        throw new PersistenceFailureException();
                    }
                }
                return(true);
            }
        }
Esempio n. 11
0
        public bool SaveSecurityQuestionAnswer(long userLoginId, string question, string answer)
        {
            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var userLoginEntity = new UserLoginEntity(userLoginId);

                if (myAdapter.FetchEntity(userLoginEntity))
                {
                    userLoginEntity.IsNew        = false;
                    userLoginEntity.HintQuestion = question;
                    userLoginEntity.HintAnswer   = _cryptographyService.Encrypt(answer);
                    userLoginEntity.IsSecurityQuestionVerified = true;
                    myAdapter.SaveEntity(userLoginEntity, true);
                    return(true);
                }
                return(false);
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        private Address Save(Address address, bool isActive)
        {
            NullArgumentChecker.CheckIfNull(address, "address");

            ValidateAddress(address);

            var addressEntity = _addressFactory.CreateAddressEntity(address);

            addressEntity.IsActive = isActive;
            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.SaveEntity(addressEntity, true))
                {
                    throw new PersistenceFailureException();
                }
                address.Id = addressEntity.AddressId;
                return(address);
            }
        }
Esempio n. 14
0
        public Van SaveVan(Van van)
        {
            if (van == null)
            {
                throw new ArgumentNullException("van", "The given van cannot be null.");
            }

            _validator.ValidateAndThrow(van);

            VanDetailsEntity vanDetailsEntity = _mapper.Map(van);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.SaveEntity(vanDetailsEntity, true))
                {
                    throw new PersistenceFailureException();
                }
            }
            return(_mapper.Map(vanDetailsEntity));
        }
Esempio n. 15
0
        public SecureHash ForceChangePassword(long userLoginId, string password, bool forceChangePassword)
        {
            var userLoginEntity = new UserLoginEntity(userLoginId);
            var securehash      = _oneWayHashingService.CreateHash(password);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (myAdapter.FetchEntity(userLoginEntity))
                {
                    userLoginEntity.IsNew = false;

                    userLoginEntity.Password               = securehash.HashedText;
                    userLoginEntity.Salt                   = securehash.Salt;
                    userLoginEntity.UserVerified           = forceChangePassword ? false : true;
                    userLoginEntity.LastPasswordChangeDate = DateTime.Now;
                    myAdapter.SaveEntity(userLoginEntity, false);
                    return(securehash);
                }
            }
            return(null);
        }
Esempio n. 16
0
        public UserLogin UpdateLoginStatus(long userLoginId, bool isSuccessfulLogin)
        {
            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var userLoginEntity = new UserLoginEntity(userLoginId);
                if (myAdapter.FetchEntity(userLoginEntity))
                {
                    userLoginEntity.IsNew         = false;
                    userLoginEntity.LoginAttempts = isSuccessfulLogin ? 0 : ++userLoginEntity.LoginAttempts;
                    userLoginEntity.IsLocked      = isSuccessfulLogin
                                                   ? false
                                                   : userLoginEntity.LoginAttempts >= 5;

                    userLoginEntity.LastLoginAttemptAt = isSuccessfulLogin ? null : (DateTime?)DateTime.Now;
                    userLoginEntity.LastLogged         = isSuccessfulLogin ? DateTime.Now : userLoginEntity.LastLogged;
                    myAdapter.SaveEntity(userLoginEntity, true);
                    return(_userLoginFactory.CreateUserLogin(userLoginEntity));
                }
                return(null);
            }
        }
Esempio n. 17
0
        public bool UpdateUsePhoneAndEmail(long userId, string phoneCell, string email)
        {
            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                var linqMetaData = new LinqMetaData(myAdapter);
                var userEntity   = linqMetaData.User.SingleOrDefault(u => u.UserId == userId);

                if (userEntity != null)
                {
                    if (!string.IsNullOrEmpty(phoneCell))
                    {
                        userEntity.PhoneCell = phoneCell;
                    }
                    if (!string.IsNullOrEmpty(email))
                    {
                        userEntity.Email1 = email;
                    }

                    return(myAdapter.SaveEntity(userEntity, true));
                }
            }
            return(false);
        }
Esempio n. 18
0
 /// <summary>
 /// Saves all dirty objects inside the enumeration passed to the persistent storage.
 /// </summary>
 /// <param name="entitiesToSave">The entities to save.</param>
 /// <param name="dataAccessAdapter">The data access adapter.</param>
 /// <returns>the amount of persisted entities</returns>
 public static int SaveEntities(IEnumerable <IEntity2> entitiesToSave, IDataAccessAdapter dataAccessAdapter)
 {
     return(entitiesToSave.Count(entity => entity.IsDirty && dataAccessAdapter.SaveEntity(entity)));
 }