public async Task <IActionResult> AddOrder(StockTransferOrderModel item) { if (ModelState.IsValid) { var resp = await aggregationController.AddNewOrder(item); if (resp.StatusCode == 200) { eventBus.PublishEvent(new AddOrderEvent { Author = item.Username, Stock = "Stock" + item.StockId.ToString(), Value = item.Value.ToString() }); return(RedirectToAction("CorrectlyAddedOrder")); } return(View("MyError", new ErrorModel(resp))); } var stockList = await stockService.GetStocks(); if (stockList == null) { var resp = StatusCode(500, "StockService is unavailable. Please, try again later"); return(View("MyError", new ErrorModel(resp))); } ViewBag.stockList = new SelectList(stockList, "Id", "Name", item.StockId); return(View()); }
public override async Task Invoke(HttpContext context) { eventBus.PublishEvent(new RequestEvent { Host = context.Connection.LocalIpAddress.ToString() + ":" + context.Connection.LocalPort.ToString(), Origin = context.Connection.RemoteIpAddress.ToString() + ":" + context.Connection.RemotePort.ToString(), Route = context.Request.Path.ToString(), RequestType = RequestType.Gateway, OccurenceTime = DateTime.Now }, true); if (context.Request.Headers.Keys.Contains(AuthorizationWord)) { await this._next(context); } else { await base.Invoke(context); } }
public async Task <ObjectResult> AddNewOrder(StockTransferOrderModel item) { var msg = ""; var stockResp = await stockService.BookStock(item); if (stockResp == null) { msg = "StockService is unavailable"; return(StatusCode(503, msg)); } if (stockResp?.StatusCode == System.Net.HttpStatusCode.NotFound) { msg = "Stock wasn't found"; return(StatusCode(404, msg)); } if (stockResp?.StatusCode == System.Net.HttpStatusCode.BadRequest) { msg = "There isn't enough place"; return(StatusCode(507, msg)); } item.Status = 10; var transfResp = await transferService.FindTransfer(item); if (transfResp?.StatusCode == System.Net.HttpStatusCode.Forbidden) { stockResp = await stockService.RefuseStock(item); msg = "TransferService is unavailable, so your order wasn't booked. Try again later"; return(StatusCode(503, msg)); } if (transfResp?.StatusCode == System.Net.HttpStatusCode.NoContent) { item.Status = item.Status + 2; stockResp = await stockService.RefuseStock(item); msg = "There are no available transfers. Try again later"; return(StatusCode(404, msg)); } if (transfResp?.StatusCode == System.Net.HttpStatusCode.BadRequest) { stockResp = await stockService.RefuseStock(item); msg = "All transfers are busy. Try again later"; return(StatusCode(507, msg)); } var trId = transfResp.Content.ReadAsStringAsync().Result; item.TransferId = Int16.Parse(trId); item.Status += 1; var ordResp = await orderService.AddOrder(item); eventBus.PublishEvent(new AddedOrderEvent { User = item.Username }); eventBus.PublishEvent(new OrderValuesEvent { Author = item.Username, Value = item.Value.ToString() }); return(StatusCode(200, msg)); }