public async Task <IEnumerable <Event> > GetEventsForTeam(long teamId)
    {
        if (teamId <= 0)
        {
            throw new ArgumentOutOfRangeException(nameof(teamId));
        }

        string str = await _httpClient.GetStringAsync(string.Format(TeamEventQueryTemplate, teamId));

        ReadDocument doc = JsonConvert.DeserializeObject <ReadDocument>(str);

        return(doc.UnpackEvents().ToList());
    }
    public async Task <long> CreateEvent(CreateEventRequest cer)
    {
        long locationId = await FindOrCreateLocationIdByName(cer.LocationName, cer.TeamId);

        WriteDocument doc = new WriteDocument
        {
            Template = new Template()
        };

        if (cer.NotifyTeam)
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "notify_team", Value = cer.NotifyTeam
            });
            doc.Template.Data.Add(new Data()
            {
                Name = "notify_team_as_member_id", Value = await GetTeamOwner(cer.TeamId)
            });
        }

        doc.Template.Data.Add(new Data()
        {
            Name = "team_id", Value = cer.TeamId
        });

        doc.Template.Data.Add(new Data()
        {
            Name = "location_id", Value = locationId
        });

        doc.Template.Data.Add(new Data()
        {
            Name = "is_game", Value = cer.IsGame
        });

        if (cer.DurationMinutes > 0)
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "duration_in_minutes", Value = cer.DurationMinutes
            });
        }

        if (cer.ArriveEarlyMinutes > 0)
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "minutes_to_arrive_early", Value = cer.ArriveEarlyMinutes
            });
        }

        if (cer.IsGame)
        {
            long opponenentId = await FindOrCreateOpponentIdByName(cer.OpponentName, cer.TeamId);

            doc.Template.Data.Add(new Data()
            {
                Name = "opponent_id", Value = opponenentId
            });

            if (!string.IsNullOrWhiteSpace(cer.GameType))
            {
                doc.Template.Data.Add(new Data()
                {
                    Name = "game_type", Value = cer.GameType
                });
                doc.Template.Data.Add(new Data()
                {
                    Name = "game_type_code", Value = cer.GameType == "Home" ? 1 : 2
                });
            }
        }
        else
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "name", Value = cer.Name
            });
        }

        if (!string.IsNullOrWhiteSpace(cer.Label))
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "label", Value = cer.Label
            });
        }

        if (!string.IsNullOrWhiteSpace(cer.Notes))
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "notes", Value = cer.Notes
            });
        }

        if (!string.IsNullOrWhiteSpace(cer.LocationDetails))
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "additional_location_details", Value = cer.LocationDetails
            });
        }

        if (cer.IsTimeTBD)
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "is_tbd", Value = true
            });
            doc.Template.Data.Add(new Data()
            {
                Name = "start_date", Value = cer.StartDate.Date
            });
        }
        else
        {
            doc.Template.Data.Add(new Data()
            {
                Name = "start_date", Value = ConvertToUtc(cer.StartDate)
            });
        }

        HttpResponseMessage resp = await _httpClient.PostAsJsonAsync("/events", doc);

        string str = await resp.Content.ReadAsStringAsync();

        ReadDocument rDoc = JsonConvert.DeserializeObject <ReadDocument>(str);

        if (resp.IsSuccessStatusCode)
        {
            return(rDoc.UnpackEvents().First().Id);
        }
        else
        {
            throw new HttpRequestException(rDoc.Collection.Error.Message);
        }
    }