/// <summary> /// Ritorna i dati di un singolo match /// </summary> /// <param name="id">Id del match</param> /// <param name="allEvents">Se true torna tutti gli eventi come se la partita fosse finita</param> /// <returns></returns> public async Task <MatchDetail> GetMatch(int id, bool allEvents) { var now = DateTime.Now; //singolo match con eventi fino al minuto attuale return(await ExecuteCall <MatchDetail, DTO.MatchDetail>( HttpMethod.Get, $"http://localhost:3000/matches/{id}", (dto) => { var det = new MatchDetail() { Id = dto.Id, StartTime = dto.StartTime, Team1 = dto.Team1, Team2 = dto.Team2, ActualMin = Mapper.ActualMin(dto.StartTime, now), Events = dto.Events?. Where(ev => { return allEvents || Mapper.IsPassedEvent(ev.Min, dto.StartTime, now); }). Select(ev => ev.ToEvent()), }; det.Team1Points = det.Events.Where(ev => ev.Team == 1).Sum(ev => ev.Points); det.Team2Points = det.Events.Where(ev => ev.Team == 2).Sum(ev => ev.Points); return det; })); }
/// <summary> /// ritorna l'elenco delle partite con il risultato al minuto attuale /// </summary> /// <returns></returns> public async Task <IEnumerable <Match> > GetResults() { var now = DateTime.Now; //elenco dei match con risultato al minuto attuale return(await ExecuteCall <List <Match>, IEnumerable <DTO.MatchDetail> >( HttpMethod.Get, $"http://localhost:3000/matches/", (dto) => { return dto?.Select(dtoMatch => { var events = dtoMatch?.Events?.Where(ev => { return Mapper.IsPassedEvent(ev.Min, dtoMatch.StartTime, now); }).Select(ev => ev.ToEvent()); return new Match() { Id = dtoMatch.Id, ActualMin = Mapper.ActualMin(dtoMatch.StartTime, now), StartTime = dtoMatch.StartTime, Team1 = dtoMatch.Team1, Team2 = dtoMatch.Team2, Team1Points = events.Where(ev => ev.Team == 1).Sum(ev => ev.Points), Team2Points = events.Where(ev => ev.Team == 2).Sum(ev => ev.Points) }; }).ToList(); })); }