public async Task <IActionResult> AddOrder(int?stockId, double?value) { if (stockId == null || value == null) { return(StatusCode(500, "Parameters are invalid")); } var item = new StockTransferOrderModel(); item.StockId = stockId.GetValueOrDefault(); item.Value = value.GetValueOrDefault(); var stockResp = await stockService.BookStock(item); if (stockResp == null) { return(StatusCode(503, "StockService is unavailable")); } if (stockResp?.StatusCode == System.Net.HttpStatusCode.NotFound) { item.OrderStatus = 20; return(StatusCode(500, "Stock wasn't found")); } if (stockResp?.StatusCode == System.Net.HttpStatusCode.BadRequest) { item.OrderStatus = 30; return(StatusCode(507, "There isn't enough place")); } item.OrderStatus = 10; var transfResp = await transferService.FindTransfer(item); if (transfResp?.StatusCode == System.Net.HttpStatusCode.Forbidden) { stockResp = await stockService.RefuseStock(item); return(StatusCode(503, "TransferService is unavailable, so recall of refusing stock was made")); } if (transfResp?.StatusCode == System.Net.HttpStatusCode.NoContent) { item.OrderStatus = item.OrderStatus + 2; stockResp = await stockService.RefuseStock(item); return(StatusCode(500, "There are no transfers")); } if (transfResp?.StatusCode == System.Net.HttpStatusCode.BadRequest) { item.OrderStatus += 3; stockResp = await stockService.RefuseStock(item); return(StatusCode(500, "All transfers are busy")); } item.OrderStatus += 1; var code = await orderService.AddOrder(item); return(Ok()); }
public async Task <IActionResult> AddOrder(int?stockId, double?value) { var msg = ""; if (stockId == null || value == null) { if (stockId == null) { if (value == null) { msg = "Stock identificator and order value are invalid"; } else { msg = "Stock identificator is invalid"; } } else { msg = "Order value is invalid"; } return(StatusCode(400, msg)); } var item = new StockTransferOrderModel(); item.StockId = stockId.GetValueOrDefault(); item.Value = value.GetValueOrDefault(); var stockResp = await stockService.BookStock(item); if (stockResp == null) { msg = "StockService is unavailable"; return(StatusCode(503, msg)); } if (stockResp?.StatusCode == System.Net.HttpStatusCode.NotFound) { item.OrderStatus = 20; msg = "Stock wasn't found"; return(StatusCode(404, msg)); } if (stockResp?.StatusCode == System.Net.HttpStatusCode.BadRequest) { item.OrderStatus = 30; msg = "There isn't enough place"; return(StatusCode(507, msg)); } item.OrderStatus = 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.OrderStatus = item.OrderStatus + 2; stockResp = await stockService.RefuseStock(item); msg = "There are no available transfers. Try again later"; return(StatusCode(500, msg)); } if (transfResp?.StatusCode == System.Net.HttpStatusCode.BadRequest) { item.OrderStatus += 3; stockResp = await stockService.RefuseStock(item); msg = "All transfers are busy. Try again later"; return(StatusCode(507, msg)); } item.OrderStatus += 1; //var code = await orderService.AddOrder(item); return(StatusCode(200)); //var stockList = await stockService.GetAllStocks(0, 0); //ViewBag.stockList = new SelectList(stockList, "Id", "Name",item.StockId); //return View(item); }
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)); }