Esempio n. 1
0
        public static async Task <List <LiveMatchViewModel> > GetGames(string teamId)
        {
            List <LiveMatchViewModel> vtr = new List <LiveMatchViewModel>();

            try
            {
                var result = await GrpcClients.GrpcClientFootballMatch(URLS.Server).RequestMatchesForTeamAsync(new Grpc.Protos.Football.ProtoMessageRequestMatches()
                {
                    TeamId = teamId
                });

                vtr = result.ListOfLiveMatchViewModel?.Select(lm => ProtoMessageLiveMatchViewModel_LiveMatchViewModel_Adapter.Map(lm))?.ToList() ?? new List <LiveMatchViewModel>();
            }
            catch (Exception)
            {
                //TODO: Notifications or something
            }
            return(vtr);
        }
Esempio n. 2
0
        public static async Task<List<LiveMatchViewModel>> GetAllLiveMatches(Func<List<string>, Task> displayNotice)
        {
            if (displayNotice == null)
                displayNotice = (n) => Task.CompletedTask; 

            List<LiveMatchViewModel> vtr = new List<LiveMatchViewModel>();
            try
            {
                if (await HasInternet(displayNotice))
                {
                    ProtoMessageRequestMatches protoMessageRequestMatches = new ProtoMessageRequestMatches() { TeamId = Variables.ArsenalTeamId };
                    var resultProto = await GrpcClients.GrpcClientFootballMatch(SanitizeMobileUrlForEmulator(URLS.Server)).RequestMatchesForTeamAsync(protoMessageRequestMatches);

                    resultProto.ListOfLiveMatchViewModel.ForEach(lm => vtr.Add(ProtoMessageLiveMatchViewModel_LiveMatchViewModel_Adapter.Map(lm)));
                }
            }
            catch (Exception)
            {
                await displayNotice(new List<string>() { "Unknown error occured" });
            }
            return vtr ?? new List<LiveMatchViewModel>();
        }
        public override async Task <ProtoMessageResponseResultOfListOfLiveMatchViewModel> RequestMatchesForTeam(ProtoMessageRequestMatches request, ServerCallContext context)
        {
            RequestMatchesForTeamQuery requestMatchesForTeamQuery = new RequestMatchesForTeamQuery(request.TeamId);
            var resultOfListOfLiveMatchViewModel = await mediator.Send(requestMatchesForTeamQuery);

            var vtr = new ProtoMessageResponseResultOfListOfLiveMatchViewModel()
            {
                Result = ProtoMessageResult_Result_Adapter.Map(resultOfListOfLiveMatchViewModel)
            };

            if (resultOfListOfLiveMatchViewModel?.ReturnedObject?.Any() ?? false)
            {
                List <ProtoMessageLiveMatchViewModel> listToAdd = resultOfListOfLiveMatchViewModel.ReturnedObject.Select(lm => ProtoMessageLiveMatchViewModel_LiveMatchViewModel_Adapter.Map(lm)).ToList();

                vtr.ListOfLiveMatchViewModel.AddRange(listToAdd);
            }
            return(vtr);
        }