Hello all,
I currently have an API on a websocket, It sends a status to my UI to the controller. When my Controller gets this status I set a viewbag or tempdata in the controller and would like this to be displayed on a partialview in my view.
If I was using ajax I could easily refresh my partial with ajax or jquery.
But since my API is calling my UI controller I am not sure if this can somehow reach the client JS from the controller like this.
Here is what I have. I would like to update my partial from the controller.
// ResultsPartial.cshtml
<div class="container row">
@if (ViewBag.Status != null)
{
<div id="box1" class="border border-primary mx-2 @ViewBag.Status" style="height:50px;width:50px;"></div>
}
else
{
<div id="box1" class="border border-primary mx-2" style="height:50px;width:50px;"></div>
}
<div id="box2" class="border border-info" style="height:50px;width:50px;"></div>
</div>
//API
[HttpPost("SendUITradeStatus")]
public async Task<IActionResult> SendUITradeStatus(BinanceStreamOrderUpdate orderUpdate)
{
if (orderUpdate != null)
{
TestVM test = new TestVM
{
Symbol = orderUpdate.Symbol,
Price = orderUpdate.Price,
Quantity = orderUpdate.Quantity,
TradeID = orderUpdate.OrderId,
Status = orderUpdate.Status.ToString(),
StopPrice = orderUpdate.StopPrice,
EventTime = orderUpdate.EventTime,
Side = orderUpdate.Side.ToString(),
ExecutionType = orderUpdate.ExecutionType.ToString()
};
//var trade = JsonSerializer.Serialize(orderUpdate);
var trade = JsonSerializer.Serialize(test);
using var client = _httpClient.CreateClient("TraderUI");
//client.SendAsync(); // test.ToString()
using var response = await client.PostAsync($"/Home/GetTradeStatus/",
new StringContent(trade, Encoding.UTF8, "application/json"));
if (response.IsSuccessStatusCode)
{
_logger.LogInformation("Success");
return Ok(trade);
}
}
return Ok();
}
//Client UI
[HttpPost]
public async Task<IActionResult> GetTradeStatus([FromBody] TestVM trade)
{
// Get List of Trades on Order
// loop to get the matching tade
// update it depending on status
// update it on the cache
/// var orderToUpdate = _marketFeed.GetTradeStatusAsync();
var lstTradeStatuses = await GetLstTradeStatuses();
if (lstTradeStatuses != null)
{
foreach (var activeTrade in lstTradeStatuses)
{
if (activeTrade.TradeID == trade.TradeID)
{
_logger.LogInformation("Trade Found in lst");
_logger.LogInformation(trade.Status);
if (trade.Status == "Canceled")
{
ViewBag.Status = "bg-success";
return PartialView("ResultsPartial");
}
}
}
}
return NoContent();
}