Example #1
0
        public Models.Account UpdateAccount(Models.Account account)
        {
            string sql = $@"UPDATE dbo.Account
                            SET TwitchId = @twitchId
                            WHERE Id = @id";

            try
            {
                _logger.LogDebug($@"{_className}: Updating Account {account.Id} to {account.TwitchId}");
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Execute(sql, new { id = account.Id, twitchId = account.TwitchId });
                }

                return(GetAccountById(account.Id));
            }
            catch (Exception e)
            {
                _logger.LogError($@"{_className}: Error updating Account {account.Id} - {e.Message}");
                return(null);
            }
        }
Example #2
0
        public int CreateAccount(Models.Account account)
        {
            int newId;

            string sql = $@"INSERT INTO dbo.Account (@twitchId) 
                            VALUES (@TwitchId)
                            SELECT CAST(SCOPE_IDENTITY() as int)";

            try
            {
                _logger.LogDebug($@"{_className}: Creating Account {account.TwitchId}");
                using (var connection = new SqlConnection(_connectionString))
                {
                    newId = connection.Query <int>(sql, new { twitchId = account.TwitchId }).Single();
                }

                return(newId);
            }
            catch (Exception e)
            {
                _logger.LogError($@"{_className}: Error creating Account {account.TwitchId} - {e.Message}");
                return(-1);
            }
        }