Пример #1
0
        public void EncryptStringTest()
        {
            string _actual = desHelper.EncryptString("YanZhiwei");

            Assert.AreEqual("S928WewvXWKJ6pIoxT91qw==", _actual);
        }
Пример #2
0
        public bool Insert(Usuario item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var           committed = 0;
            bool          result    = false;
            UserPasswords oUserPass = new UserPasswords();
            Password      oPass     = new Password();

            try
            {
                //if (session != null)
                //    _repositoryUsuario.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                var validator = EntityValidatorFactory.CreateValidator();
                if (validator.IsValid(item))
                {
                    var _repoPass     = _repositoryUsuario.GetRepository <Password>();
                    var _repoUserPass = _repositoryUsuario.GetRepository <UserPasswords>();

                    _unitOfWorkAsync.BeginTransaction();

                    oUserPass = item.UserPasswords.FirstOrDefault();
                    oPass     = oUserPass.Password;
                    //oUserPass = item.UserPasswords.FirstOrDefault();
                    //Password
                    string _srtEncrypt = desHelper.EncryptString(oPass.Password1);
                    //string _strDecrypt = desHelper.DecryptString("39S4D8vXqfk=");
                    //oPass.Password1 = item..Password;
                    oPass.PasswordHash  = _srtEncrypt;
                    oPass.TrackingState = TrackingState.Added;
                    ////////_repoPass.Insert(oPass);
                    //committed = _unitOfWorkAsync.SaveChanges();
                    //var oPassTemp = _repoPass.Queryable().Where(x => x.PasswordHash == _srtEncrypt).FirstOrDefault();

                    item.TrackingState = TrackingState.Added;
                    _repositoryUsuario.Insert(item, false);
                    //var oUser = _repositoryUsuario.Queryable().Where(x => x.AccountName == item.AccountName).FirstOrDefault();
                    //committed = _unitOfWorkAsync.SaveChanges();

                    oUserPass.IdUsuario     = item.Id;
                    oUserPass.IdPassword    = oPass.Id;
                    oUserPass.TrackingState = TrackingState.Added;
                    //_repoUserPass.Insert(oUserPass);

                    committed = _unitOfWorkAsync.SaveChanges();
                    result    = _unitOfWorkAsync.Commit();

                    // Domain Services?
                    //_repositoryUsuario.Insert(Mapper.Map<Dominio.Entidades.Usuario>(item));
                    //_repositoryUsuario.Insert(item);
                }
                else
                {
                    throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(item));
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkAsync.Rollback();
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            //return committed > 0;
            return(result);
        }