Ejemplo n.º 1
0
        public async void CreateNewAccountAsync(DbAccountsData dbAccData, MySqlConnectionSettings connSettings)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(dbAccData.Login))
                {
                    _logger.UpdateLog("Login cannot be empty!");
                    return;
                }

                bool success = false;

                using (MySqlDbManager dbManager = new MySqlDbManager(connSettings))
                {
                    BoxedData connStartData = await dbManager.StartConnectionTaskStart();

                    bool connStartSuccess = (bool)connStartData.Data;
                    if (!String.IsNullOrEmpty(connStartData.Msg))
                    {
                        _logger.UpdateLog(connStartData.Msg);
                    }

                    if (connStartSuccess)
                    {
                        BoxedData accCreationData = await dbManager.AddAccountsDataTaskStart(dbAccData);

                        int accId = (int)accCreationData.Data;

                        if (!String.IsNullOrEmpty(accCreationData.Msg))
                        {
                            _logger.UpdateLog(accCreationData.Msg);
                        }

                        if (accId > -1)
                        {
                            _logger.UpdateLog($"Created new account, acc_id [{accId}]!");

                            if (_accountData != null)
                            {
                                _accountData.AddAccountData
                                (
                                    new DbAccountsData
                                    (
                                        accId,
                                        dbAccData.Login,
                                        dbAccData.PassEncrypted,
                                        DbAccountsData.PasswordType.Encrypted,
                                        dbAccData.AccessLevel
                                    )
                                );
                            }

                            success = true;
                        }
                    }
                    else
                    {
                        _logger.UpdateLog("Cannot connect to database!");
                    }
                }

                if (success)
                {
                    _logger.UpdateLog("Account created successfully!");
                }
            }
            catch (Exception exception)
            {
                _logger.UpdateLog($"Account creation failure: {exception.Message}");
            }
        }