Exemplo n.º 1
0
        // Account

        public AccountDB GetOrAddAccountByAccountText(string accountText)
        {
            DBManager db = new DBManager();
            HostType hostType = MyUtils.GetHostTypeFromAccount(accountText);
            string accountTypeName = AccountTypeDB.FromTypeCodeToString(hostType);
            AccountDB account = db.GetAccountByUserNameAndAccountTypeName(accountText, accountTypeName);

            if(account.Id <= 0) // add new
            {
                AccountTypeDB type = db.GetAccountTypeByName(accountTypeName);
                int accountID = db.AddNewAccount(accountText, "", type.Id);

                account = db.GetAccountById(accountID);
                account.HostType = hostType;
            }
            account.AccountTypeName = accountTypeName;
            return account;
        }
Exemplo n.º 2
0
        public int CheckUpdateAccount(int id, string user, string pass, int a_type)
        {
            DBManager db = new DBManager();
            int contactCount = db.GetContactCountByAccountId(id);

            if (contactCount == 0)
            {
                AccountDB acc = db.GetAccountByUserNameAndAccountTypeId(user, a_type);
                int accId = acc.Id;
                accId = accId > 0 ? accId : id;

                return (db.UpdateAccountById(accId, user, pass, a_type) > 0 ? accId : -1);
            }
            else
            {
                AccountDB account = db.GetAccountById(id);
                if (account.Username.Equals(user) && account.AccountTypeId == a_type)
                {
                    return (db.UpdateAccountById(id, user, pass, a_type) > 0 ? id : -1);
                }
                else
                {
                    AccountDB acc = db.GetAccountByUserNameAndAccountTypeId(user, a_type);
                    int accId = acc.Id;
                    if (accId > 0)
                    {
                        return (db.UpdateAccountById(accId, user, pass, a_type) > 0 ? accId : -1);
                    }
                    else
                    {
                        return db.AddNewAccount(user, pass, a_type);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public int AddNewAccount(string username, string password, int accountTypeId)
 {
     DBManager db = new DBManager();
     return db.AddNewAccount(username, password, accountTypeId);
 }