public IActionResult Post([FromBody] OrderViewModel newOrder) { using (SurfboardContext context = new SurfboardContext()) { Customer c = new Customer(); c.Address = newOrder.Customer.Address; c.FirstName = newOrder.Customer.FirstName; c.LastName = newOrder.Customer.LastName; context.Customers.Add(c); context.SaveChanges(); Order o = new Order(); o.OrderDate = DateTime.Now; o.CustomerId = c.Id; context.Orders.Add(o); context.SaveChanges(); // Skapa orderrader!!!! foreach (var item in newOrder.Cart) { OrderRow or = new OrderRow(); or.OrderId = o.Id; or.SurfBoardId = item.Id; or.Price = item.Price; or.SizeId = item.SizeId; context.OrderRows.Add(or); context.SaveChanges(); } return(Created("/orders", o)); } }
public IActionResult Post([FromBody] Customer newCustomer) { using (SurfboardContext context = new SurfboardContext()) { context.Customers.Add(newCustomer); context.SaveChanges(); } return(Created("/customers", newCustomer)); }
public IActionResult Delete(int id) { using (SurfboardContext context = new SurfboardContext()) { Customer deleteCustomer = context.Customers.First(c => c.Id == id); context.Customers.Remove(deleteCustomer); context.SaveChanges(); } return(Ok()); }
public IActionResult Delete(int id) { using (SurfboardContext context = new SurfboardContext()) { Order deleteOrder = context.Orders.First(o => o.Id == id); context.Orders.Remove(deleteOrder); context.SaveChanges(); } return(Ok()); }