Ejemplo n.º 1
0
        public List <AccountModel> GetAccountInfosWithAttributes( )
        {
            List <AccountModel> tmpAccountModels = null;

            var tmpAccountEntities = this.accountDataAccess.GetAccountEntities( );

            if (tmpAccountEntities != null && tmpAccountEntities.Count > 0)
            {
                tmpAccountModels = new List <AccountModel>(tmpAccountEntities.Count);

                var tmpAttributeEntities = this.attributeDataAccess.GetAccountAttributeEntities();
                foreach (AccountEntity entity in tmpAccountEntities)
                {
                    var tmpAccountModel = AccountConvertor.Convert(Account.CurrentAccount.SecretKey, entity);
                    tmpAccountModels.Add(tmpAccountModel);

                    var tmpAccountId = tmpAccountModel.AccountId;
                    if (tmpAttributeEntities != null)
                    {
                        var tmpAccountAttributes = tmpAttributeEntities.Where(attribute => attribute.AccountId == tmpAccountId).OrderBy(attribute => attribute.Order).ThenBy(attribute => attribute.AttributeId).ToList();
                        if (tmpAccountAttributes != null && tmpAccountAttributes.Count > 0)
                        {
                            tmpAccountAttributes.ForEach(item =>
                            {
                                tmpAccountModel.Attributes.Add(AccountConvertor.ConvertAttribute(Account.CurrentAccount.SecretKey, item));
                            });
                        }
                    }
                }
            }

            return(tmpAccountModels);
        }
Ejemplo n.º 2
0
        public AccountModel GetAccountInfo(string accountGuid)
        {
            AccountModel tmpAccountInfo = null;

            var tmpAccountEntity = this.accountDataAccess.GetAccountEntityByGuid(accountGuid);

            if (tmpAccountEntity != null)
            {
                tmpAccountInfo = AccountConvertor.Convert(Account.CurrentAccount.SecretKey, tmpAccountEntity);
            }

            return(tmpAccountInfo);
        }
Ejemplo n.º 3
0
        public IList <AccountModel> GetDeletedAccounts( )
        {
            IList <AccountModel> tmpAccountModels = null;

            var tmpAccountEntities = this.accountDataAccess.GetRecycleBinEntities( );

            if (tmpAccountEntities != null && tmpAccountEntities.Count > 0)
            {
                tmpAccountModels = new List <AccountModel>(tmpAccountEntities.Count);
                foreach (AccountEntity entity in tmpAccountEntities)
                {
                    tmpAccountModels.Add(AccountConvertor.Convert(Account.CurrentAccount.SecretKey, entity));
                }
            }

            return(tmpAccountModels);
        }
Ejemplo n.º 4
0
        public IList <AccountModel> GetAccountInfos(int catalogId)
        {
            IList <AccountModel> tmpAccountModels = null;

            var tmpAccountEntities = this.accountDataAccess.GetAccountEntities(catalogId);

            if (tmpAccountEntities != null && tmpAccountEntities.Count > 0)
            {
                tmpAccountModels = new List <AccountModel>(tmpAccountEntities.Count);
                foreach (AccountEntity entity in tmpAccountEntities)
                {
                    tmpAccountModels.Add(AccountConvertor.Convert(Account.CurrentAccount.SecretKey, entity));
                }
            }

            return(tmpAccountModels);
        }
Ejemplo n.º 5
0
        public AccountModel GetAccountInfo(int accountId)
        {
            AccountModel tmpAccountInfo = null;

            var tmpAccountEntity = this.accountDataAccess.GetAccountEntity(accountId);

            if (tmpAccountEntity != null)
            {
                tmpAccountInfo = AccountConvertor.Convert(Account.CurrentAccount.SecretKey, tmpAccountEntity);
                var tmpAttributeEntities = attributeDataAccess.GetAccountAttributeEntities(accountId);
                if (tmpAttributeEntities != null)
                {
                    foreach (var item in tmpAttributeEntities)
                    {
                        tmpAccountInfo.Attributes.Add(AccountConvertor.ConvertAttribute(Account.CurrentAccount.SecretKey, item));
                    }
                }
            }

            return(tmpAccountInfo);
        }
Ejemplo n.º 6
0
        public bool CreateAccount(AccountModel item, DbTransaction transaction = null)
        {
            bool tmpExecuteResult = false;

            var tmpAccountEntity = AccountConvertor.Convert(Account.CurrentAccount.SecretKey, item);

            tmpAccountEntity.UpdateTime = tmpAccountEntity.CreateTime = System.DateTime.Now;

            var tmpDataBaseAccess = (IDataBase)this.accountDataAccess;

            using (var tmpDataConnection = tmpDataBaseAccess.CreateConnection(tmpDataBaseAccess.ConnectionString))
            {
                DbTransaction tmpDataTransaction = null;
                try
                {
                    tmpDataConnection.Open( );
                    tmpDataTransaction = tmpDataConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);

                    tmpExecuteResult = this.accountDataAccess.Create(tmpAccountEntity, tmpDataTransaction);
                    if (tmpExecuteResult)
                    {
                        item.AccountId = tmpAccountEntity.AccountId;

                        var tmpAttributeEntities = new List <AccountAttributeEntity>();
                        if (item.Attributes.Count > 0)
                        {
                            foreach (var attribute in item.Attributes)
                            {
                                var tmpAttributeEntity = AccountConvertor.ConvertAttribute(Account.CurrentAccount.SecretKey, attribute);
                                tmpAttributeEntity.AccountId = item.AccountId;
                                tmpAttributeEntities.Add(tmpAttributeEntity);
                            }
                        }

                        if (tmpAttributeEntities.Count > 0)
                        {
                            tmpExecuteResult = this.attributeDataAccess.New(tmpAttributeEntities, tmpDataTransaction);
                        }
                    }

                    tmpDataTransaction.Commit( );
                }
                catch (System.SystemException exception)
                {
                    if (tmpDataTransaction != null)
                    {
                        tmpDataTransaction.Rollback( );
                    }

                    loger.Error(exception);

                    throw exception;
                }
                finally
                {
                    if (tmpDataConnection.State == System.Data.ConnectionState.Open)
                    {
                        tmpDataConnection.Close( );
                    }
                }
            }

            return(tmpExecuteResult);
        }
Ejemplo n.º 7
0
        public bool MoveToRecycleBin(AccountModel item)
        {
            var tmpAccountEntity = AccountConvertor.Convert(Account.CurrentAccount.SecretKey, item);

            return(this.accountDataAccess.MoveToRecycleBin(tmpAccountEntity));
        }
Ejemplo n.º 8
0
        public bool UpdateAccount(AccountModel item)
        {
            bool tmpExecuteResult = false;

            var tmpDataBaseAccess = (IDataBase)this.accountDataAccess;

            using (var tmpDataConnection = tmpDataBaseAccess.CreateConnection(tmpDataBaseAccess.ConnectionString))
            {
                DbTransaction tmpDataTransaction = null;

                tmpDataConnection.Open( );
                tmpDataTransaction = tmpDataConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);

                var tmpOldAccountEntity = this.accountDataAccess.GetAccountEntity(item.AccountId);
                if (tmpOldAccountEntity != null)
                {
                    var tmpNewAccountEntity = AccountConvertor.Convert(Account.CurrentAccount.SecretKey, item);
                    tmpNewAccountEntity.CreateTime = tmpOldAccountEntity.CreateTime;
                    tmpOldAccountEntity.UpdateTime = tmpNewAccountEntity.UpdateTime = System.DateTime.Now;

                    try
                    {
                        tmpExecuteResult = true;

                        bool tmpNeedUpdate = !tmpNewAccountEntity.Equals(tmpOldAccountEntity);
                        if (tmpNeedUpdate)
                        {
                            tmpOldAccountEntity.Name      = tmpNewAccountEntity.Name;
                            tmpOldAccountEntity.URL       = tmpNewAccountEntity.URL;
                            tmpOldAccountEntity.LoginName = tmpNewAccountEntity.LoginName;
                            tmpOldAccountEntity.Password  = tmpNewAccountEntity.Password;
                            tmpOldAccountEntity.Email     = tmpNewAccountEntity.Email;
                            tmpOldAccountEntity.Mobile    = tmpNewAccountEntity.Mobile;
                            tmpOldAccountEntity.Comment   = tmpNewAccountEntity.Comment;

                            tmpExecuteResult = this.accountDataAccess.Update(tmpOldAccountEntity, tmpDataTransaction);
                        }

                        if (tmpExecuteResult)
                        {
                            var tmpInsertEntities = new List <AccountAttributeEntity>( );
                            var tmpUpdateEntities = new List <AccountAttributeEntity>( );
                            var tmpDeleteEntities = new List <AccountAttributeEntity>( );

                            var tmpNewAttributeEntities = new List <AccountAttributeEntity>( );
                            if (item.Attributes.Count > 0)
                            {
                                foreach (var attribute in item.Attributes)
                                {
                                    var tmpAttributeEntity = AccountConvertor.ConvertAttribute(Account.CurrentAccount.SecretKey, attribute);
                                    tmpAttributeEntity.AccountId = item.AccountId;

                                    if (tmpAttributeEntity.AttributeId <= 0)
                                    {
                                        tmpInsertEntities.Add(tmpAttributeEntity);
                                    }
                                    else
                                    {
                                        tmpNewAttributeEntities.Add(tmpAttributeEntity);
                                    }
                                }
                            }

                            var tmpOldAttributeEntities = this.attributeDataAccess.GetAccountAttributeEntities(item.AccountId, tmpDataConnection);
                            if (tmpOldAttributeEntities != null)
                            {
                                foreach (var tmpOldAttribute in tmpOldAttributeEntities)
                                {
                                    bool tmpFoundItem = false;
                                    foreach (var tmpNewAttribute in tmpNewAttributeEntities)
                                    {
                                        if (tmpOldAttribute.AttributeId == tmpNewAttribute.AttributeId)
                                        {
                                            tmpFoundItem = true;
                                            if (!tmpNewAttribute.Equals(tmpOldAttribute))
                                            {
                                                tmpUpdateEntities.Add(tmpNewAttribute);
                                            }

                                            break;
                                        }
                                    }

                                    if (!tmpFoundItem)
                                    {
                                        tmpDeleteEntities.Add(tmpOldAttribute);
                                    }
                                }
                            }

                            if (tmpDeleteEntities.Count > 0)
                            {
                                tmpExecuteResult = this.attributeDataAccess.Delete(tmpDeleteEntities, tmpDataTransaction);
                            }

                            if (tmpInsertEntities.Count > 0)
                            {
                                tmpExecuteResult = this.attributeDataAccess.New(tmpInsertEntities, tmpDataTransaction);
                            }

                            if (tmpUpdateEntities.Count > 0)
                            {
                                tmpExecuteResult = this.attributeDataAccess.Update(tmpUpdateEntities, tmpDataTransaction);
                            }
                        }

                        tmpDataTransaction.Commit( );
                    }
                    catch (System.SystemException exception)
                    {
                        if (tmpDataTransaction != null)
                        {
                            tmpDataTransaction.Rollback( );
                        }

                        loger.Error(exception);

                        throw exception;
                    }
                    finally
                    {
                        if (tmpDataConnection.State == System.Data.ConnectionState.Open)
                        {
                            tmpDataConnection.Close( );
                        }
                    }
                }
            }

            return(tmpExecuteResult);
        }