public async Task <ActionResult> CreateOrder() { CreateOrderVm createOrderVm = new CreateOrderVm(); //get customers var graphQLClient = new GraphQLClient("http://localhost:13515/api/school"); GraphQLQuery graphQLQuery = GraphQLHelper.GetGraphQLQuery("GetCustomers"); var heroRequest = new GraphQLRequest { Query = graphQLQuery.Body, OperationName = "GetAllCustomers" }; var graphQLResponse = await graphQLClient.PostAsync(heroRequest); string json = JsonConvert.SerializeObject(graphQLResponse.Data); var result = JsonConvert.DeserializeObject <Dictionary <string, List <Customer> > >(json); List <Customer> customers = new List <Customer>(); foreach (var obj in result.Values.ElementAt(0)) { customers.Add(obj); } createOrderVm.Customers = customers; //get employees graphQLQuery = GraphQLHelper.GetGraphQLQuery("GetEmployees"); heroRequest = new GraphQLRequest { Query = graphQLQuery.Body, OperationName = "GetAllEmployees" }; graphQLResponse = await graphQLClient.PostAsync(heroRequest); json = JsonConvert.SerializeObject(graphQLResponse.Data); var result2 = JsonConvert.DeserializeObject <Dictionary <string, List <Employee> > >(json); List <Employee> employees = new List <Employee>(); foreach (var obj in result2.Values.ElementAt(0)) { employees.Add(obj); } createOrderVm.Employees = employees; //get shippers graphQLQuery = GraphQLHelper.GetGraphQLQuery("GetShippers"); heroRequest = new GraphQLRequest { Query = graphQLQuery.Body, OperationName = "GetAllShippers" }; graphQLResponse = await graphQLClient.PostAsync(heroRequest); json = JsonConvert.SerializeObject(graphQLResponse.Data); var result3 = JsonConvert.DeserializeObject <Dictionary <string, List <Shipper> > >(json); List <Shipper> shippers = new List <Shipper>(); foreach (var obj in result3.Values.ElementAt(0)) { shippers.Add(obj); } createOrderVm.Shippers = shippers; return(View(createOrderVm)); }
public async Task <ActionResult <Order> > CreateOrder([FromBody] CreateOrderVm order) { var result = _service.CreateOrder(order.Products, order.UserId); if (result == null) { return(StatusCode(StatusCodes.Status400BadRequest)); } return(StatusCode(StatusCodes.Status200OK, result)); }
// GET: Orders/Create public async Task <IActionResult> Create() { var model = new CreateOrderVm(); model.ProductDetails = await _context.Products.Select(x => new OrderProductDetails { ProductId = x.Id, Product = x.Name, Category = x.Category.Name }).ToListAsync(); return(View(model)); }
public ActionResult CreateOrder([Bind(Include = "Description,Price,Quantity,Status,CustomerId")] CreateOrderVm purchaseOrder) { if (ModelState.IsValid) { PurchaseOrder order = Mapper.Map <CreateOrderVm, PurchaseOrder>(purchaseOrder); this.servise.CreateOrder(order); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(this.servise.CustomersList(), "Id", "FullName", purchaseOrder.CustomerId); return(View(purchaseOrder)); }
public int PostOrderCreate(CreateOrderVm model) { try { OrderCreateInfVm order = new OrderCreateInfVm(); order.CustomerId = model.CustomerId; order.ShipmentAddId = model.ShipmentAddId; order.BillingAddId = model.BillingAddId; order.PaymentType = model.PaymentType; order.PaidAmount = model.PaidAmount; string[] array = model.ArticleCodeStrings.ToArray(); string combindedString = string.Join(",", array); var res = _unitOfWork.OrderCreate.PostOrderCreate(combindedString, order); return(res); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Create([FromForm] CreateOrderVm order) { if (ModelState.IsValid) { var newOrder = new Order(); newOrder.CustomerName = order.CustomerName; newOrder.Zip = order.Zip; newOrder.Address = order.Address; newOrder.State = order.State; newOrder.IsShipped = order.IsShipped; newOrder.OrderProducts = order.ProductDetails.Select(x => new OrderProduct { ProductId = x.ProductId, Quantity = x.Quantity }).ToList(); _context.Orders.Add(newOrder); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public IActionResult OrderCreate(CreateOrderVm data) { var res = _orderCreateManager.PostOrderCreate(data); return(Ok(res)); }