コード例 #1
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);
        }