Exemplo n.º 1
0
        public async Task <long> AddUserToTeam(TeamUserAssociationModel model)
        {
            var id = await GetTeamUserAssociationId(model.TeamId, model.UserId);

            if (id.HasValue)
            {
                throw new ArgumentException("User is already member of team");
            }

            await using var command = _connection.CreateCommand();
            command.CommandType     = CommandType.StoredProcedure;
            command.CommandText     = "AddUserToTeam";
            command.Parameters.AddWithValue("@TeamId", model.TeamId);
            command.Parameters.AddWithValue("@UserId", model.UserId);

            if (_connection.State != ConnectionState.Open)
            {
                await _connection.OpenAsync();
            }
            await using var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection);

            await reader.ReadAsync();

            return((long)reader.GetDecimal(0));
        }
Exemplo n.º 2
0
        public async Task RemoveUserFromTeam(TeamUserAssociationModel model)
        {
            var id = await GetTeamUserAssociationId(model.TeamId, model.UserId);

            if (!id.HasValue)
            {
                throw new ArgumentException("User is not member of team");
            }

            await using var command = _connection.CreateCommand();
            command.CommandType     = CommandType.StoredProcedure;
            command.CommandText     = "RemoveUserFromTeam";
            command.Parameters.AddWithValue("@Id", id);

            if (_connection.State != ConnectionState.Open)
            {
                await _connection.OpenAsync();
            }
            await command.ExecuteNonQueryAsync();
        }