Beispiel #1
0
 public IActionResult DeletePizzaFromOrderPost(OrderOfPizzas orderOfPizzas)
 {
     try
     {
         _orderService.RemovePizzaFromOrder(orderOfPizzas);
         return(RedirectToAction("Details", new { id = orderOfPizzas.OrderId }));
     }
     catch (Exception e)
     {
         return(View("ExceptionView"));
     }
 }
Beispiel #2
0
        public IActionResult DeletePizzaFromOrder(OrderOfPizzas orderOfPizzas)
        {
            if (orderOfPizzas == null)
            {
                return(View("BadRequest"));
            }

            try
            {
                return(View(orderOfPizzas));
            }
            catch (Exception ex)
            {
                return(View("ExceptionView"));
            }
        }
Beispiel #3
0
        public void RemovePizzaFromOrder(OrderOfPizzas orderOfPizzas)
        {
            //get the order
            Order order = _orderRepository.GetById(orderOfPizzas.OrderId);

            if (order == null)
            {
                //log
                throw new Exception($"Order with id {orderOfPizzas.OrderId} was not found!");
            }

            PizzaOrder pizzaOrderDelete = order.PizzaOrders.FirstOrDefault(p => p.PizzaId == orderOfPizzas.PizzaId);

            order.PizzaOrders.Remove(pizzaOrderDelete);

            _orderRepository.Update(order);
        }