public bool Delete(PasswordChangelog passwordChangelog)
        {
            var passwordChangelogEntity = Mapper.Map <PasswordChangelog, PasswordChangelogEntity>(passwordChangelog);

            using (IDataAccessAdapter myAdapter = PersistenceLayer.GetDataAccessAdapter())
            {
                if (!myAdapter.DeleteEntity(passwordChangelogEntity))
                {
                    throw new PersistenceFailureException();
                }
                return(true);
            }
        }
Пример #2
0
        public bool Update(long userLoginId, SecureHash usedSecureHash, long createdByOrgRoleUserId)
        {
            var passwordlist = _passwordChangelogRepository.GetOldPasswordList(userLoginId);
            var count        = _configurationSettingRepository.GetConfigurationValue(ConfigurationSettingName.PreviousPasswordNonRepetitionCount);

            if (passwordlist == null || passwordlist.Count() < Convert.ToInt32(count))
            {
                var passwordChangeLog = new PasswordChangelog()
                {
                    UserLoginId            = userLoginId,
                    CreatedByOrgRoleUserId = createdByOrgRoleUserId,
                    Password    = usedSecureHash.HashedText,
                    Salt        = usedSecureHash.Salt,
                    DateCreated = DateTime.Now,
                    Sequence    = passwordlist == null ?1: passwordlist.Count() + 1
                };
                return(_passwordChangelogRepository.Save(passwordChangeLog));
            }

            if (passwordlist.Count() > Convert.ToInt32(count))
            {
                var extraInDb       = passwordlist.Count() - Convert.ToInt32(count);
                var toBeDeletedList = passwordlist.OrderBy(x => x.Sequence).Take(extraInDb);

                foreach (var passwordChangelog in toBeDeletedList)
                {
                    _passwordChangelogRepository.Delete(passwordChangelog);
                }
                passwordlist.ToList().ForEach(x => x.Sequence = x.Sequence - extraInDb);
                passwordlist = passwordlist.Where(x => !toBeDeletedList.Select(d => d.Id).Contains(x.Id));
            }

            if (passwordlist.Any())
            {
                var oldestPassword = passwordlist.OrderBy(x => x.Sequence).First();
                passwordlist.ToList().ForEach(x => x.Sequence = x.Sequence - 1);
                oldestPassword.Sequence               = Convert.ToInt32(count);
                oldestPassword.UserLoginId            = userLoginId;
                oldestPassword.CreatedByOrgRoleUserId = createdByOrgRoleUserId;
                oldestPassword.Password               = usedSecureHash.HashedText;
                oldestPassword.Salt        = usedSecureHash.Salt;
                oldestPassword.DateCreated = DateTime.Now;

                foreach (var passwordChangeLog in passwordlist)
                {
                    _passwordChangelogRepository.Save(passwordChangeLog);
                }
            }

            return(true);
        }