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 ActionResult <List <Order> > Get(int id) { using (SurfboardContext context = new SurfboardContext()) { Customer Customer = context.Customers.First(c => c.Id == id); return(Ok(Customer)); } }
public ActionResult <List <Order> > Get() { using (SurfboardContext context = new SurfboardContext()) { List <Customer> Customers = context.Customers.ToList(); return(Ok(Customers)); } }
public ActionResult <List <Size> > Get(int id) { using (SurfboardContext context = new SurfboardContext()) { Size Size = context.Sizes.First(c => c.Id == id); return(Ok(Size)); } }
public ActionResult <List <Size> > Get() { using (SurfboardContext context = new SurfboardContext()) { List <Size> Sizes = context.Sizes.ToList(); return(Ok(Sizes)); } }
public ActionResult <List <Surfboard> > Get(int id) { using (SurfboardContext context = new SurfboardContext()) { Surfboard Board = context.Surfboards.First(c => c.Id == id); return(Ok(Board)); } }
public ActionResult <List <Surfboard> > Get() { using (SurfboardContext context = new SurfboardContext()) { List <Surfboard> Surfboards = context.Surfboards.ToList(); return(Ok(Surfboards)); } }
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()); }
public ActionResult <List <Order> > Get(int id) { using (SurfboardContext context = new SurfboardContext()) { Order Order = context.Orders .Include(c => c.Customer) .Include(or => or.OrderRows) .ThenInclude(or => or.Surfboard) .Include(or => or.OrderRows) .ThenInclude(or => or.Size) .First(o => o.Id == id); return(Ok(Order)); } }
public ActionResult <List <Order> > Get() { using (SurfboardContext context = new SurfboardContext()) { List <Order> Orders = context.Orders .Include(c => c.Customer) .Include(or => or.OrderRows) .ThenInclude(or => or.Surfboard) .Include(or => or.OrderRows) .ThenInclude(or => or.Size) .ToList(); return(Ok(Orders)); } }