//public async Task<IActionResult> Create([Bind("Id,OrderId,CustomerId,EmployeeId,OrderDate,RequiredDate,ShippedDate,ShipVia,Freight,ShipName,ShipAddress,ShipCity,ShipRegion,ShipPostalCode,ShipCountry")] Orders orders) public async Task <IActionResult> Create([FromForm] OrdersForCreation ordersForCreation, IFormCollection formCollection) { if (ModelState.IsValid) { ordersForCreation.OrderDetails = Utilities.GetOrderDetails(0, formCollection); await _serviceOrders.CreateOrder(ordersForCreation); return(RedirectToAction(nameof(Index))); } //ViewData["EmployeeId"] = new SelectList(_context.Employees, "Id", "Id", orders.EmployeeId); regionsListItems = await Utilities.FillRegionsCollection(_configuration); ViewData["Regions"] = regionsListItems; return(View(ordersForCreation)); }
public async Task <OrdersForCreation> CreateOrder(OrdersForCreation orderToCreate) { var serializedOrderToCreate = JsonConvert.SerializeObject(orderToCreate); var request = new HttpRequestMessage(HttpMethod.Post, $"{apiRoute}"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType)); request.Content = new StringContent(serializedOrderToCreate); request.Content.Headers.ContentType = new MediaTypeHeaderValue(mediaType); var response = await _httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); var content = await response.Content.ReadAsStringAsync(); var createdOrder = JsonConvert.DeserializeObject <OrdersForCreation>(content); return(createdOrder); }