public override Task <H2HReply> Details(H2HRequest request, ServerCallContext context) { if (request.Player1 == null || request.Player2 == null) { return(Task.FromResult(new H2HReply { Success = false })); } var h2h = GetHeadToHead(request.Player1, request.Player2); if (h2h == null) { return(Task.FromResult(new H2HReply { Success = false })); } // Ensure order of player IDs match var w1 = string.Equals(h2h.Id1, request.Player1, StringComparison.InvariantCultureIgnoreCase) ? h2h.Record1 : h2h.Record2; var w2 = string.Equals(h2h.Id2, request.Player2, StringComparison.InvariantCultureIgnoreCase) ? h2h.Record2 : h2h.Record1; return(Task.FromResult(new H2HReply { Won1 = (uint)w1, Won2 = (uint)w2 })); }
public override Task <H2HReply> DetailsDemo(H2HRequest request, ServerCallContext context) { var rnd = new Random(DateTime.Now.Second); return(Task.FromResult(new H2HReply { Won1 = (uint)rnd.Next(0, 10), Won2 = (uint)rnd.Next(0, 10) })); }
public IActionResult Details(string p1, string p2, string sender) { // Call the RPC service const string host = "localhost"; const int port = 50051; var serviceUrl = host + ":" + port; var channel = new Channel(serviceUrl, ChannelCredentials.Insecure); var client = new Tennis.H2H.H2HClient(channel); var request = new H2HRequest() { Player1 = p1, Player2 = p2 }; var response = sender == "detailsdemo" ? client.DetailsDemo(request) : client.Details(request); var model = new H2HViewModel { Player1 = p1, Player2 = p2, Won1 = response.Won1, Won2 = response.Won2 }; return(View(model)); }