public async Task <bool> Add(NOrders NOrders) { _context.NOrders.Add(NOrders); await _context.SaveChangesAsync(); return(true); }
public async Task <ActionResult <NOrders> > PostOrders(Orders order) { if (order.Pizzas.IsNullOrEmpty() && order.PreMadePizzaIds.IsNullOrEmpty() && order.SidesIds.IsNullOrEmpty()) { return(UnprocessableEntity()); } else { NOrders nOrder = new NOrders { CustomerId = order.CustomerId, OrderTime = DateTime.Now //order.OrderTime, }; await _orderRepo.Add(nOrder); if (order.Pizzas != null) { foreach (var pizza in order.Pizzas) { NPizzas nPizza = new NPizzas { CheeseTypeId = pizza.CheeseTypesId, CrustTypeId = pizza.CrustTypesId, SauceTypeId = pizza.SauceTypesId, Size = pizza.Size, Name = pizza.Name }; await _pizzaRepo.Add(nPizza); await _orderRepo.Add(new OrderPizzas { NOrderId = nOrder.Id, NPizzaId = nPizza.Id }); if (pizza.ToppingsId != null) { foreach (var topping in pizza.ToppingsId) { await _pizzaRepo.Add(new PizzaToppings { NPizzaId = nPizza.Id, ToppingId = topping }); } } } } if (order.SidesIds != null) { foreach (var sideId in order.SidesIds) { OrderSides os = new OrderSides { NOrderId = nOrder.Id, SideId = sideId }; await _orderRepo.Add(os); } } if (order.PreMadePizzaIds != null) { foreach (var PreMadePizzaId in order.PreMadePizzaIds) { OrderPreMadePizzas opmp = new OrderPreMadePizzas { NOrderId = nOrder.Id, PreMadePizzaId = PreMadePizzaId }; await _orderRepo.Add(opmp); } } return(CreatedAtAction("GetOrders", new { id = nOrder.Id }, nOrder.Id)); } }
public Task <bool> Add(NOrders NOrders) { throw new NotImplementedException(); }