public async Task <IActionResult> IndexAsync() { var cart = _cart.GetCart(Request); if (cart.Items.Count < 1) { return(Redirect("/")); } OrderInfoRequest orderInfo = new OrderInfoRequest(); orderInfo.CustomerId = Int32.Parse(User.Claims.Where(c => c.Type == "UserId").First().Value); cart.Items.ForEach(cartItem => { orderInfo.Items.Add(new Item { ProductId = cartItem.ProductId, Quantity = cartItem.Quantity }); }); var(statusCode, result) = await _order.AddOrder(orderInfo); if (result == null) { ViewData["OrderError"] = "ERROR!!!"; return(View()); } ViewData["OrderResult"] = result; _cart.ClearCartCookie(Response); return(View()); }
public async Task <IActionResult> AddOrder([FromBody] OrderInfoRequest orderInfo) { if (!ModelState.IsValid || orderInfo.Items.Count < 1) { return(BadRequest()); } var productList = new List <ProductViewModel>(); for (int i = 0; i < orderInfo.Items.Count; i++) { var p = await _product.GetProductAsync(orderInfo.Items[i].ProductId); if (p == null) { return(BadRequest()); } p.Quantity = orderInfo.Items[i].Quantity; productList.Add(p); } var orderItems = _mapper.Map <List <OrderItems> >(productList); var result = await _order.AddOrder(orderInfo.CustomerId, orderItems); if (result == null) { return(BadRequest()); } orderItems.ForEach(oi => oi.Order_Id = result.Id); result.OrderItems = _mapper.Map <List <OrderItemsViewModel> >(orderItems); return(Ok(result)); }
public async Task <(HttpStatusCode, OrdersViewModel)> AddOrder(OrderInfoRequest orderInfo) { var uri = API.Orders.AddOrder(); var postData = new StringContent(JsonSerializer.Serialize(orderInfo), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(uri, postData); var statusCode = response.StatusCode; if (!response.IsSuccessStatusCode) { return(statusCode, null); } using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializer.DeserializeAsync <OrdersViewModel>(responseStream); return(statusCode, result); }
public static void GetOrderInfoExample() { /***Initialize the calling object*/ IdaxApiRestClient idaxApiRestClient = IdaxConfig.init(); /**Request parameter encapsulation**/ string symbol = IdaxApiConstants.ETH_BTC; OrderInfoRequest orderInfoRequest = new OrderInfoRequest(); orderInfoRequest.key = IdaxConfig.API_KEY; orderInfoRequest.pair = symbol; orderInfoRequest.pageIndex = 1; orderInfoRequest.pageSize = 20; orderInfoRequest.timestamp = DateTime.UtcNow.UnixTimeStamp(); orderInfoRequest.orderId = 9799L; /**Call remote interface**/ OrderInfoEntry orderInfoEntry = idaxApiRestClient.getOrderInfo(orderInfoRequest); }
public OrderInfoResponse GetOrderInfo(string orderCode) { var order = new OrderInfoRequest(); client.EndPoint = baseUri + "GetOrderInfo"; order.ApiKey = apiKey; order.ApiSecretKey = apiSecretKey; order.ClientID = int.Parse(clientId); order.Password = password; order.OrderCode = orderCode; client.PostData = JsonConvert.SerializeObject(order); client.ContentType = RestClient.ContentTypeConst.Json; var response = JsonConvert.DeserializeObject <OrderInfoResponse>(client.MakeRequest()); if (response == null) { return(new OrderInfoResponse()); } return(response); }