public async Task AddOrder(PaymentVM pvm) { using (OrderServiceContext ctx = new OrderServiceContext()) { Orders order = new Orders() { OrderAdress = pvm.DeliveryAdress, OrderDate = DateTime.Now, FirstName = pvm.FirstName, LastName = pvm.LastName, Email = pvm.Email }; ctx.Orders.Add(order); ctx.SaveChanges(); foreach (Product p in pvm.Cart.Products) { ctx.OrderLine.Add(new OrderLine() { ProductId = p.Id, OrderId = order.Id, Total = p.Price }); } System.Diagnostics.Debug.WriteLine("ORDER ADDED: " + order.ToString()); await ctx.SaveChangesAsync(); } }
public IHttpActionResult PostAddress(_Orders orders) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string userId = User.Identity.GetUserId(); var ordermodel = new Orders { UserId = userId, AddressId = orders.orderdata.AddressId, Status = orders.orderdata.Status, Total = orders.orderdata.Total, ActualDate = orders.orderdata.ActualDate, ServiceDate = orders.orderdata.ServiceDate, StartTime = orders.orderdata.StartTime, EndTime = orders.orderdata.EndTime, PaymentMethod = orders.orderdata.PaymentMethod, StripeCreditCardId = orders.orderdata.StripeCreditCardId, last4 = orders.orderdata.last4 }; using (var db = new OrdersContext()) { db.Orders.Add(ordermodel); db.SaveChanges(); } OrderService orderservicemodel; for (int i = 0; i < orders.orderservicedata.Count; i++) { orderservicemodel = new OrderService { OrderId = ordermodel.OrderId, ServiceId = orders.orderservicedata[i].ServiceId, Price = orders.orderservicedata[i].ServicePrice, VehicleId = orders.orderservicedata[i].VehicleId }; using (var db = new OrderServiceContext()) { db.OrdersService.Add(orderservicemodel); db.SaveChanges(); } } return(CreatedAtRoute("DefaultApi", new { }, orders)); }
public bool Add(Order order) { _context.Add(order); _context.SaveChanges(); return(true); }